Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Blog Reader iPhone App Exploring the Master-Detail Template Passing Data To The Detail View

Returns error on Xcode 7.0

When press item returns: 2015-10-19 12:27:52.899 BlogReader[4138:232343] -[UINavigationController setDetailItem:]: unrecognized selector sent to instance 0x7ff944831600 (lldb)

1 Answer

Yup. The video is pretty old. (It's from 2012!) The code that'll work is this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"showDetail"]) {

        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; // Sets the index path
        NSString *object = [ _titlesArray objectAtIndex: [ indexPath row ] ]; // Sets the title of blog as the variable object

        // You need to cast the destination view controller as a DetailViewController, or else it'll give an ugly error...

        DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
        [controller setDetailItem:object];

        /* This just sets the nav bar of the destination view controller to have a button that can change the display of the view controller.
         Only introduced in iOS 8
        */

        controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
        controller.navigationItem.leftItemsSupplementBackButton = YES;
    }
}