ViewDidLoad and WillHideViewController Not Called When Use UINavigationController as Child of UISplitViewController on iOS13

Viewed 347

I have an apps with UISplitViewController as Root View, but for children of this view I use UINavigationController. Although Master and Detail View is UIViewController, but I added this to UINavigationController before I set as Child of UISplitViewController, I did this because I need Title and UIBarButton, and also because I share this view for iPad and iPhone.

So this the snippet of my code:

MasterView _masterView = new MasterView;
UINavigationController _masterViewNavigation = new UINavigationController(_masterView);

DetailView _detailView = new DetailView;
UINavigationController _detailView Navigation = new UINavigationController(_detailView);

_splitView.ViewController = new UIViewController[]{_masterView, _detailView};

Everything was working before iOS 13. But when I run on iOS 13, ViewDidLoad of _masterView wasn’t called. While I need this to change image view on _masterView when the user makes changes on _detailView, although _masterView not shown.

Also WillHideViewController is not called, while I need this to add UIBarButtonItem on _detailView to show and hide _masterView.

Can you help me to find the solution?

1 Answers

Issue with iOS 13 Split view controller using IB. If you have navigation controller embedded to Master/Detail view controller it just loads the navigation controller.

To fix that issue create a custom class from UISplitViewController and assign that to your splitviewcontroller in storyboard and programatically add Navigation controller and masterViewcontroller to that UISplitViewController. That should load your view properly. This code goes in the viewdidload or willappear of the UISplitviewcontroller class. Sample code. in Obj c

    MasterViewController *master = [[MasterViewController alloc] init];
    UINavigationController *tableViewNavigationController = [[UINavigationController alloc] initWithRootViewController:master];
    UINavigationController *navC = [[UINavigationController alloc] init];
    self.viewControllers = [NSArray arrayWithObjects:tableViewNavigationController,navC, nil];

This fixed my issue , Had similar issue after iOS13. Hope that help !

Related