1

I am making an app where the user selects a couple of different inputs (non-actual example: car brand, miles and color). Every selection has some defined values to choose from, which are each one or two sentences long. I am wondering what the best way to display this is.

A picker view will not work well since some options are two sentences long. I could use a modal or push view with tables in them, but I am not sure what is the most "correct" way according to conventions? Let us say that I use a modal view, is it against any convention to dismiss it automatically when the user selects something in the table?

EDIT: To make myself more clear, below is an example of the hierarchy I am talking about.

Example

Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82

1 Answers1

1

You can dismiss the current modal view controller any time you want. There is no 'correct way' of doing this. When the user selected a table view cell, you can dismiss the modal view controller in the UITableViewDelegate method:

- (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. */

}

And a table view is your best choice for displaying options with long text. You can adjust the height of each cell in the table view through the UITableViewDelegate method:

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

Also, if you'd like to calculate the height of any piece of text, you can do it like this:

// 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;