Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drill down tableview in storyboards

I am trying to make a drill down table with storyboards in a Tab bar app. I am having a problem with working out how to get each row in a main table to point to other different tables.

This is the code I have used to detect row selection.

-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
    TableViewController *table = [self.storyboard instantiateViewControllerWithIdentifier:@"table"];
    [self.navigationController pushViewController:table animated:YES];

}

How do I proceed please?

like image 540
MacUser Avatar asked Dec 30 '11 19:12

MacUser


3 Answers

The real beauty to UIStoryBoards are the segues. 1. You can link one prototype cell push segue to another different table view controller 2. You can link one prototype cell push segue loop back to itself for drill downs.

[self performSegueWithIdentifier:@"segueID" sender:MyObject];

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  if([segue.identifier isEqualToString:@"segueID"]) segue.destinationViewController.chosenCell = sender;
}

If the segue is from the cell click, the sender is that of the cell and you can get it's indexpath from the table, and pass new information to the upcoming view controller. If you want the cell to take various paths when clicked, keep the didSelectRowAtIndexPath and call performSegueWithIndetifier so you can choose left or right.

Tutorial: http://jleeiii.blogspot.com/2012/05/uistoryboard-power-drill-batteries.html

GitHub: http://www.github.com/jllust/UIStoryboardExamples

like image 101
InitJason Avatar answered Oct 19 '22 17:10

InitJason


I was extremely frustrated with this, as the storyboards with tableviews is really not covered ANYWHERE. I literally almost pulled my hair out trying to figure this out. So my frustration is your luck!

Comparing your code to mine, yours looks fine other than the fact that in the initial didSelectRowAtIndexPath: method, you have *_strong, which should not have the _strong part. It should just be like this: (NSIndexPath *)indexPath {

Additionally, be careful in when you are referring to the instantiateViewControllerWithIdentifier in Interface Builder. I accidentally filled out the name of the instance variable under 'TITLE' instead of 'IDENTIFIER'

I hope this helps. I completely understand your frustration.

like image 40
Mark Avatar answered Oct 19 '22 18:10

Mark


In your storyboard, if the content is Static Cells, you can ctrl-drag from the specific row to a Navigation Controller. Then connect the Navigation Controller to your next table. Look at this screen shot. http://cl.ly/1V2y0v202y390U0A351x

My guess is that progromatically, you'll need to do something similar, segue to a NavigationController which has a table view controller as it's root view.

like image 1
dbrajkovic Avatar answered Oct 19 '22 17:10

dbrajkovic