1

我正在制作一个应用程序,用户可以在其中选择几个不同的输入(非实际示例:汽车品牌、里程和颜色)。每个选择都有一些定义的值可供选择,每个值都是一两个句子长。我想知道展示它的最佳方式是什么。

选择器视图不能很好地工作,因为某些选项有两个句子长。我可以使用带有表格的模态视图或推送视图,但我不确定根据惯例最“正确”的方式是什么?假设我使用模态视图,当用户在表格中选择某些内容时自动关闭它是否违反任何约定?

编辑:为了让自己更清楚,下面是我正在谈论的层次结构的一个例子。

例子

4

1 回答 1

1

您可以随时关闭当前的模态视图控制器。没有“正确的方法”可以做到这一点。当用户选择一个表格视图单元格时,您可以在 UITableViewDelegate 方法中关闭模式视图控制器:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

  [tableView deselectRowAtIndexPath:indexPath animated:YES];

  /* dismiss your modal view controller

   through the UIViewController method
   - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
   or through the UINavigationViewController method
   - (UIViewController *)popViewControllerAnimated:(BOOL)animated

   depending on the way you presented it in the first place. */

}

表格视图是显示长文本选项的最佳选择。您可以通过 UITableViewDelegate 方法调整表格视图中每个单元格的高度:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   return /*appropriate cell height in order to accommodate long text */;
}

此外,如果您想计算任何文本的高度,您可以这样做:

// get the table view width
CGFloat tableViewWidth = [tableView bounds].size.width;

// get your piece of text
NSString *text = /*your text*/

CGFloat textHeight = [text sizeWithFont:[UIFont systemFontOfSize:18]/*or any font you want*/
                      forWidth:tableViewWidth 
                      lineBreakMode:NSLineBreakByWordWrapping].height;
于 2013-03-31T18:39:51.620 回答