Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing UIBarButtonItem in the UISplitViewController

I've got missing navigationItem with popover in my right-hand view controller inside UISplitViewController. Simply the button do not appears when I'm rotating iPad to portrait orientation. The code is just fine, I have used the same one (not absolutely of course) many times, but right now i have got this weird bug.

- (void)splitViewController:(UISplitViewController *)svc 
     willHideViewController:(UIViewController *)aViewController 
          withBarButtonItem:(UIBarButtonItem *)barButtonItem 
       forPopoverController:(UIPopoverController *)pc
{
    barButtonItem.title = aViewController.title;
    self.navigationItem.rightBarButtonItem = barButtonItem;
/*
this method gets called, class is set to be delegate of split view,
barButtonItem && self.navigationItem are not nils.
*/
}

- (void)splitViewController:(UISplitViewController *)svc 
     willShowViewController:(UIViewController *)aViewController 
  invalidatingBarButtonItem:(UIBarButtonItem *)button
{
    self.navigationItem.rightBarButtonItem = nil;
}

All of this stuff gets created using the code like this...

UISplitViewController *svc = [[UISplitViewController alloc] init];
UINavigationController *rightNav = [[UINavigationController alloc] init];
DetailViewController *dvc = [[DetailViewController alloc] initWithSomeArgs:args];
[rightNav pushViewController:dvc animated:NO];
svc.delegate = dvc;
svc.viewControllers = [NSArray arrayWithObjects:tabBarController, rightNav, nil]; 
// tabBar is good, not nil and working well on the iPhone
[self.window addSubview:svc.view];
[dvc release]; [rightNav release];

I have no idea why that doesn't work, and I need to figure it out ASAP. Help me please.

like image 855
Woyo Avatar asked Nov 14 '22 04:11

Woyo


1 Answers

I had a similar issue. I had a Master-Detail application and was using Storyboards. My Detail View Controller was embedded in a Navigation Controller. The UISplitViewControllerDelegate methods were implemented properly and they were being called when the device rotated. The bar button was being added correctly, but wasn't visible.

Cause of the problem: In Storyboards in my Detail View Controller, I had added a navigation bar manually, since I didn't see any navigation bar otherwise. However, this was not the same navigation bar as the one I was adding the button to. The correct navigation bar was hidden in Storyboards, and thus not visible in my app.

Solution: I went to my Detail View Controller in Storyboards and deleted the navigation bar I had added manually. Then, I clicked on the Navigation Controller. Under 'Attributes inspector', I checked the box labeled 'Shows Navigation Bar'. Now, the correct bar was visible in both my Navigation Controller and my Detail View Controller, as well as my app.

like image 162
Dastan Avatar answered Dec 30 '22 07:12

Dastan