UISplitViewController not calling delegate methods

2019-07-14 02:46发布

I setup a storyboard based on the Master-Detail Application, embed the detail view in a navigation controller, and add a new table view controller object which I will use as a second detail view controller.

I then push the new detail view controller with the following code (instead of a segue because I am pushing both a root view and a detail view controller at the same time. Only the detail view code is shown).

// Push the detailView view controller:
NewClass *newViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"test"];

newViewController.navigationItem.hidesBackButton = YES;
self.splitViewController.delegate                = newViewController;

[self.detailViewController pushViewController:newViewController animated:YES];

This works perfectly, EXCEPT that the splitView delegate methods are never called before or after the push. If I do this while in portrait mode, after it pushes the detailViewController, the button to drop down the masterView popover does not show up UNTIL I rotate to landscape mode and then back to portrait mode.

How can I cause the willHideViewController/willShowViewController split view controller delegate methods to be called or manually cause them to be called?

1条回答
趁早两清
2楼-- · 2019-07-14 03:22

So from what I found, it doesn't call the method because the orientation hasn't changed.

What you have to do is to pass the button from the presenting view controller since it's already tied to the popover like this:

if(self.navigationItem.leftBarButtonItem != nil) {
    newViewController.navigationItem.leftBarButtonItem = self.navigationItem.leftBarButtonItem;
}

// Push the newViewController
查看更多
登录 后发表回答