1

Hi i'm working on a standard Master-Detail Applicaton.

When you create a master-detail application in xcode (i mean the one that it propose when creating a new project), xcode creates a navigation controller, a table view and a detail view, the default behavior when you click the uitableview cell is to go on the detail view. I would like instead to go on another table view (that of course i had already created in the storyboard). My purpose is to show a list of filtered values ​​on the basis of what I clicked (the cell clicked) on the first table view.

So i try to accomplish this from the graphical storyboard, i try to ctrl-drag an arrow from the first-standard table view to the second-new one. Selecting manual segue = show. And I even deleted the "original" arrow that link the first-standard table view to the detail view (the one proposed by xcode).

But when i click on a table view cell in the simulator, the clicked cell becomes gray and nothing happens.

How can I make a second filtered table view appear when I click on a first' table view cell? What should i do to accomplish this?

Ps. i am a very beginner of iOS programming, objective-c and cocoa touch framework. I xcode tag because i would like to know what can be done from within the storyboard (graphically) to accomplish what i need to do.

Johwhite
  • 323
  • 4
  • 18

2 Answers2

1

This is very basic. In short: before you switch to the new TableViewController you fill it with filtered data in prepareForSegue according to which cell was clicked.

Apple doc to this subject: Apple Doc - Navigating a Data Hierarchy with Table Views A good answer is here: https://stackoverflow.com/a/19806545/1195661

Community
  • 1
  • 1
palme
  • 2,499
  • 2
  • 21
  • 38
1

If you want to show a "detail" table view when you click onto a "master" table view cell you can do this with ctrl-drag. Start from the prototype cell (selecting it) of the master view to the second table view, in the storyboard, then choose show detail option to create a segue.

click on the segue and check its name in the attributes inspector, it should be showDetail , as in the MasterViewController.swift file you should look at this function, in prepareForSegue you can set the filtered results: Also: setDetailItem:object should be changed to another function, since the tableView scene you have created will not have the detailItem property , you can add a property in the h file and set it from prepareForSegue

#pragma mark - Segues

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSDate *object = self.objects[indexPath.row];
        [[segue destinationViewController] setDetailItem:object];
    }
}
Jaimy
  • 227
  • 1
  • 8
  • I've done this, but the problem is not filtering data, the problem is that *it does nothing*. I've put a breakpoint on the if statement and the execution never stops (like it doesn't pass over the breakpoint). – Johwhite Jul 17 '15 at 15:07
  • is it showing the next scene or it is stuck in the masterView and the segue is not working at all? – Jaimy Jul 17 '15 at 15:10
  • It is stuck in the masterView! The only thing is that the clicked cell becomes gray. – Johwhite Jul 17 '15 at 15:11
  • do you have this when you click the segue in storyboard? https://www.dropbox.com/s/33bv1f6cux4431c/Screen%20Shot%202015-07-17%20at%2011.14.13%20AM.png?dl=0 – Jaimy Jul 17 '15 at 15:14
  • If you click + on the top right corner of the MasterView when the app is running , AND then click on the newly added cell : it will move to the detailView you have. The problem is that if you don't click + , there are no cells! Let me know if you see this. I suggest you do this by starting with single view application :) – Jaimy Jul 17 '15 at 15:25
  • Yes! However i did it, now it works. Pratically i was doing ctrl-drag from the top of master tableViewController (wrong place). In your image i noticed that the **prototype cell was highlighted**. I tried ctrl-drag from the prototype cell to the detail and now it works. Thank you for helping me! – Johwhite Jul 17 '15 at 15:27
  • Glad I could help! :) – Jaimy Jul 17 '15 at 15:35