Nick
Nick

Reputation: 6025

iPad segue error in Xcode

Noob Xcode question here.

I have a basic Master-Detail setup.

When I choose an item in the master list, it brings a second "master" sidebar with the details, instead of updating the details page.

So I start with this:

I click on "Nick Jones" and get this: enter image description here

The storyboard looks like this: enter image description here

But if I click on the Master View Controller, the Detail View Controller changes size to this: enter image description here

I'm trying to adapt the tutorial "Your Second iOS App" tutorial to iPad (rather than iPhone). The key segue page is here. I've reestablished a segue link between the navigation controller and the Detail View Controller because it doesn't work hardly at all without it, but I'm clearly doing it wrongly.

Thanks.

Upvotes: 2

Views: 988

Answers (1)

Rob
Rob

Reputation: 437937

A couple of observations:

  1. The obvious problem is the type of segue you have from the master view controller to the detail view controller. It should be a "replace" segue, and when you select that segue and click on the attributes inspector, make sure you specify the destination of the "detail split":

    detail split

  2. As an aside, the reason that the storyboard is a little confused on the UI, is that you've got two segues into that detail view controller, one from the details view of the split view controller (and thus the squarish shape of the details scene), and another from the master view controller (and thus the, incorrect, narrow shape of the details scene). The poor Interface Builder is probably sitting there thinking "hey, did you want me to use this scene as the details for a split view, or as a replacement for the master view controller?!?" My previous point resolves this conflict, but this explains why, in your current storyboard, the shape of the details scene changes based upon which scene you currently have selected.

  3. If you're going to do it this way, I'd suggest that you might want the segue from the master scene to the details scene to actually go from the master to the navigation controller scene, not to the details scene itself:

    go to navigation controller

  4. To be quite blunt, though, having described how to fix the segue, you shouldn't be using a segue! Create a blank new "master-detail" project and see what it does. You'll notice that it looks more like:

    enter image description here

You really only want the segue from the master scene to the details scene if you're changing the details view controller to a different scene. But you're not doing that. You probably only want to tell the details view controller that the object it's looking at has changed and that it should reloadData. And given that your details view controller is a tableview, itself, the the master view controller would have a method that does something like (a) tell the detail view controller what detail item it's looking at; and (b) tell it to reloadData. So it might look something like:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDate *object = _objects[indexPath.row];
    self.detailViewController.detailItem = object;

    [self.detailViewController.tableView reloadData];
}

You can make it work either way, but I would have thought that this latter approach might make more sense.

Upvotes: 3

Related Questions