Missing UIBarButtonItem in UISplitViewController

I lost navigationItem with a popover in my right view controller inside a UISplitViewController. It’s just that the button doesn’t appear when I rotate the iPad to portrait orientation. The code is fine, I have used the same (not quite sure) many times, but right now I have this strange error.

- (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 these materials are created using 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 this is not working, and I need to understand this as soon as possible. Help me please.

+4
source share
2 answers

I had a similar problem. I had a Master-Detail app and I used storyboards. The My Detail View controller has been integrated into the navigation controller. The UISplitViewControllerDelegate methods were implemented correctly, and they were called when the device was rotated. The bar button was added correctly, but was not visible.

Cause of problem: In the storyboards in my detail view manager, I added a navigation bar manually, because otherwise I did not see any navigation bars. However, this was not the same navigation bar as the add button. The correct navigation bar was hidden in Storyboards and thus not displayed in my application.

Solution . I went to my storyboard detailed view controller and deleted the navigation bar, which I added manually. Then I clicked on the navigation controller. In the "Attribute Inspector" section, I checked the "Shows navigation bar" checkbox. Now the correct bar was visible both in my navigation controller, and in my detail view manager, as well as in my application.

+1
source

It looks like you missed the link for links between your DetailViewController and UISplitViewController.

0
source

Source: https://habr.com/ru/post/1336410/


All Articles