在iOS中显示长文本选项的最佳方式?

在iOS中显示长文本选项的最佳方式?,ios,uipickerview,Ios,Uipickerview,我正在制作一个应用程序,用户可以选择几个不同的输入(非实际示例:汽车品牌、里程和颜色)。每个选择都有一些定义的值可供选择,每个值都有一两句话长。我想知道最好的展示方式是什么 选择器视图不会很好地工作,因为有些选项是两句话。我可以使用模式视图或推式视图,其中包含表,但根据惯例,我不确定最“正确”的方式是什么?假设我使用的是模态视图,当用户在表中选择某个内容时自动取消它是否违反任何约定 编辑: 为了让我自己更清楚,下面是一个我正在谈论的层次结构的例子 您可以随时关闭当前的模态视图控制器没有“正确的方

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

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

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


您可以随时关闭当前的模态视图控制器没有“正确的方法”。当用户选择表视图单元格时,可以在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. */

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   return /*appropriate cell height in order to accommodate long text */;
}
而表格视图是显示长文本选项的最佳选择。 可以通过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. */

}
- (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;

您可以随时关闭当前模态视图控制器没有“正确的方法”。当用户选择表视图单元格时,可以在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. */

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   return /*appropriate cell height in order to accommodate long text */;
}
而表格视图是显示长文本选项的最佳选择。 可以通过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. */

}
- (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;