I have implemented a MGSplitViewController where I have 6 rows in the masterviewcontroller and each one loads a new UIViewController into the detailviewcontroller – I have followed Apples example project on using multiple detail view controllers. But I am having a couple of weird problems with it.
Firstly, upon the initial load the first selected detailviewcontroller displays perfectly. However, when I select different rows in the masterviewcontroller to change the detail view controller the row is selected but the detailviewcontroller does not change – this continues on like this for several clicks – then everything works fine.
Well almost, now when the new detailviewcontroller actually loads sometimes the views become overlaid. For instance if I first select a detailviewcontroller with a tableview and then select one that just has some buttons in it – the buttons appear overlaid onto of the tableview. If anyone can understand what I am doing wrong please let me know. Here is my did selectrow method.
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
/*
Create and configure a new detail view controller appropriate for the selection.
*/
switch (indexPath.row) {
case 1:
{
self.splitViewController.detailViewController = self.postViewController;
// popover = [[UIPopoverController alloc] initWithContentViewController:self.postViewController];
// [popover presentPopoverFromRect:CGRectMake(200, 0, 100, 100)
// inView:self.splitViewController.view
// permittedArrowDirections:UIPopoverArrowDirectionAny
// animated:YES];
break;
}
case 2:
self.splitViewController.detailViewController = self.latestViewController;
break;
case 3:
self.splitViewController.detailViewController = self.categoriesViewController;
break;
case 4:
self.splitViewController.detailViewController = self.messagesViewController;
break;
case 5:
self.splitViewController.detailViewController = self.searchViewController;
break;
case 6:
self.splitViewController.detailViewController = self.accountViewController;
break;
default:
break;
}
}
There seems to be a bug in MGSplitViewController where it doesn’t remove the previous detailViewController’s view. To solve this, add the following line above your switch statement: