Search code examples
iphoneipaduitableviewuiviewcontrolleruisplitviewcontroller

Changing Views with MGSplitView Controller


In the app that io am creating, i have a custom copy of UISplitView Controller, MGSplitViewController. I have implemented it into my project which started off with the MultipleDetailViews sample code from apple.

I have come across a problem where i cant seem to switch between viewcontrollers. When i push the tableview cells, the detailview controller should change according the the nib assigned, however that doesn't happen.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

/*
 Create and configure a new detail view controller appropriate for the selection.
 */
NSUInteger row = indexPath.row;

UIViewController *detailViewController = nil;


if (row == 0) {
    FirstDetailViewController *newDetailViewController = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
    detailViewController = newDetailViewController;
}

if (row == 1) {
    SecondDetailViewController *newDetailViewController = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailView" bundle:nil];
    detailViewController = newDetailViewController;
}

// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];

[detailViewController release];

Normally this code would be enough to change the views in the original Multiple Detail View code.

has anyone run into a similar problem? any ideas?


Solution

  • You're just creating new view controllers. You're not adding them anywhere. You add view controllers to the split view controller by using its viewControllers property.

    EDIT: I've used MGSplitViewController, but I never tried to change the detail view like that. I just pushed the new detail view controller onto the navigation controller. Is there a specific reason for wanting to change the detail view controller entirely?