UISplitViewController portrait mode missing UIBarButtonItem

狂风中的少年 提交于 2020-01-24 02:43:19

问题


I have an application with a UISplitViewController, when I launch the app under potrait mode it's missing the "Group" UIBarButtonItem. I need to turn to landscape mode and back to potrait to make it appear. When I launch it in landscape mode it is there. Here's some screenshot to make it clear:

This is when the application is launched at portrait mode

This is in landscape mode, after rotating it from portrait mode:

This is after rotating back to portrait mode from landscape mode:


回答1:


The same thing happened to me a couple days ago. You just have to make sure that the detail view is delegate of the splitView. If you try to set the delegate in the detail view's viewDidLoad, it won't be set until after the splitView loads (with the root tableView controller). That is why it is doesn't get placed until you switch to landscape and back. The best way to set the delegate is either in your app delegate implementation file (when you create the UISplitViewController, which would be the best idea) or in the root tableView controller with something like

- (void)viewDidLoad {
    self.splitViewController.delegate = [self.splitViewController.viewControllers objectAtIndex:1];
}

That makes the detail view delegate, so when it loads after the tableView controller loads, it will call your splitViewController:willHideViewController:... method.

Of course, this may not be the situation you have. I'm just assuming that since I had the exact same behavior, it is probably the same cause. If this doesn't do the trick, just say so and we'll get to the cause




回答2:


I couldn't figure out this problem either, as my code and IB connections seemed identical to what Apple's Multiple Detail Views sample source code had.

I was able to get it to work properly by changing the reference from self.splitViewController (a property of the left view controller's class) in the 2nd to last line to the svc passed in automatically to the method. I had noticed in the debugger that the former had not been instantiated yet for some reason. (memory location was 0x00000000).

- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc {

// Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.
barButtonItem.title = @"Menu";
self.popoverController = pc;
self.rootPopoverButtonItem = barButtonItem;
UIViewController <SubstitutableDetailViewController> *detailViewController = [self.splitViewController.viewControllers objectAtIndex:1];
[detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];

}



来源:https://stackoverflow.com/questions/6147284/uisplitviewcontroller-portrait-mode-missing-uibarbuttonitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!