2

All I wan't is to display a UIPickerView at the bottom of a UITableViewController.

The problem is I can't just add the picker as subview, since it's a UITableView. badum tss. The UIActionSheet hack also won't work since iOS 7 so don't have any more ideas.

Did anyone else had the same issue and can help me figure it out?

yinkou
  • 5,756
  • 2
  • 24
  • 40

1 Answers1

0

Assuming you are trying to add it to the actual bottom of the tableView rather than just the bottom of the screen, try adding it as a subview to the Footerview.

//Create whatever kind of pickerView here.

UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, self.pickerView.frame.size.height)];

[footerView addSubview:self.pickerView];

self.tableView.tableFooterView = footerView;

If you are trying to add it as an action sheet but that's not working for you on iOS 7, an answer would be creating your own ActionSheet as just a UIView that contains the pickerView and animates in and out when you need it to.

Eric
  • 5,671
  • 5
  • 31
  • 42
  • I'm sorry. I have meant at the bottom of the screen. Anyway, custom animation won't work cause you can't add it to the tableView as a subView. But you have given me the best idea so far by adding it directly to the main window! thanks. – yinkou Mar 24 '14 at 17:09
  • Is your ViewController a standard UIViewController with a tableview in it or is it a UITableViewController – Eric Mar 24 '14 at 17:12
  • As stated in the question, it is an UITableViewController. – yinkou Mar 24 '14 at 17:15
  • K well if you would like to add subviews I would convert it to a UIViewController, set it as your UITableViewDelegate/Datasource, add the tableView, then you can add any subviews you want - Animations and all – Eric Mar 24 '14 at 17:18
  • Yeah i know, but i would keep the convenience of static cells. – yinkou Mar 24 '14 at 17:19
  • What do you mean by static cells. Anything you can do in a UITableViewController you can do in a UIViewController with a tableview as a subview – Eric Mar 24 '14 at 17:27
  • A Tableview with static cell is only available for a UITableViewController. It is a content type of a tableView and lets you make the content of the TableView in Storyboard without any code. See [here](https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW2) under Static cells. – yinkou Mar 24 '14 at 17:33
  • I understand what that means, but I still don't know why you are trying to tell me you can't do that with a UIViewController. I am 100% sure you can, as I just tried it out. Step 1. Create a UIViewController in storyboard. Step 2. Add a UITableView subview to this controller. Step 3. Select the tableView. Step 4. In the attributes inspector, Select content, and choose static cells. This is exactly what you need to create your own popup pickerView. – Eric Mar 24 '14 at 17:39
  • If i do that, i get the warning "Static table views are only valid when embedded in UITableViewController instances". – yinkou Mar 24 '14 at 17:42
  • Weird, I'm not getting an error. Ok, well if that doesn't work, Create a UITableViewController as you did with static cells, and add it as a childViewController of another UIViewController. That way it has all the capabilities a normal UITableViewController would have, but will be embedded in a UIViewController http://stackoverflow.com/a/12574544/904355 – Eric Mar 24 '14 at 17:46