I am kind of new to IOS development and have ran into an issue I haven't been able to find an answer to.
I am using a UISplitViewController with two separate Navigation Controllers. One for the popover and one for the detail. Basically, I need to be able to assign various Detail Views as the delegate to the Navigation Controller because some may show the popover and some may not.
The current code im using on viewDidLoad is:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UISplitViewController *splitViewController = (UISplitViewController *)appDelegate.window.rootViewController;
splitViewController.delegate = self;
The problem is that the delegate is only being assigned to the First view that uses this. When using this in other view the previous view's delegate is still being called.
Anyone have any idea what I may be doing wrong? Thanks.
I figured it out.
The UISplitViewController documentation says
In complex configurations, you need a separate custom controller object to manage the master >and detail view controllers and mediate between them. The custom controller is the split view >controller’s delegate, and is responsible for communicating with the current detail view >controller to show and hide the popover bar button item.
So what I was doing was wrong from the start. I fixed it by putting all the SplitView logic into one view controller like this:
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController: (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
BOOL hide = YES;
// Get current view from navigation controller
UINavigationController *detailNavigationController = [svc.viewControllers objectAtIndex:1];
NSInteger topIndex = detailNavigationController.viewControllers.count - 1;
UIViewController *detailviewController = [detailNavigationController.viewControllers objectAtIndex:topIndex];
// Perform different actions based on visible view
NSString *detailTitle = detailviewController.title;
if([detailTitle isEqualToString:@"Controller_Name"]) {
hide = NO;
}
return hide;
}