Navigating to rootViewController of non-visible UINavigationController CRASH
- by Bertie
First off I'n not sure if this is exactly the issue... but it appears to be central to the problem. There are vast gaps in what I know and this may be something very obvious.
I have a split view controller with various Master and Detail Views. From one 'menu' branch I want to return to the rootView of both the Master & Detail Navigation Controllers when the user taps a 'Done' button. Initially I had the button positioned on the navigation bar of the master view.
This is the code I was using:
- (IBAction)doneClicked:(id)sender
{
UINavigationController *detailNav = [self.splitViewController.viewControllers objectAtIndex:1];
NSArray *allDetailViewControllers = detailNav.viewControllers;
HomePage *destinationDetailVC = [allDetailViewControllers objectAtIndex:0];
destinationDetailVC.splitViewBarButtonItem = self.splitViewButton;
[detailNav popToRootViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:NO];
}
That works fine but if the device is in portrait mode it means the user has to open the menus to access the button. So I decided to put the 'Done' button onto the detail view NavBar instead. Using a delegate declared in the detailVC and adopted by the masterVC I am now using this method:
- (void)theUserClickedDoneInTheDetailView:(DetailVC *)controller withButton:(UIBarButtonItem *)splitViewButton
{
UINavigationController *detailNav = [self.splitViewController.viewControllers objectAtIndex:1];
NSArray *allDetailViewControllers = detailNav.viewControllers;
HomePage *destinationDetailVC = [allDetailViewControllers objectAtIndex:0];
destinationDetailVC.splitViewBarButtonItem = splitViewButton;
[detailNav popToRootViewControllerAnimated: NO];
[self.navigationController popToRootViewControllerAnimated:NO];
}
Both methods are in the MasterVC.m file The only difference between the two is that on is passed a UIBarButtonItem to use and the other has already had it passed when it is set in the detail view. That seems to be working because I do get a button.
When the device is in Landscape mode both methods work fine. All behaviour as expected.
When the device is in Portrait the first method still works fine.
The second appears to work fine and the detail view is the rootView, the button for the menus is there BUT, as soon as I turn the device to landscape it crashes.
The only thing I can think of is that it is because the masterView is hidden.
Can anyone help...?