Search code examples
objective-cios13

UINavigationController: pushViewController not working in iOS 13, remains on same page


I am calling a method from performSelectorOnMainThread which calls pushViewController. But the view is not loaded and remains on the same page. This case was working in iOS 12 but not in iOS 13.

- (void)toNextView:{
    ImageViewController * vc = ImageViewController.new;
    [self performSelectorOnMainThread:@selector(nextScreenWithVC:) withObject:vc waitUntilDone:NO];
}
- (void)nextScreenWithVC:(UIViewController *)vc
{
    [self.parent.navigationController pushViewController:vc animated:NO];
}

This function does not loads the ImageViewController. The same code works in iOS 12.


Solution

  • I figured out the solution by reading the iOS 13 release note. To understand some changes i used the following link. https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle?language=objc

    The app is going in background state before calling pushViewController and another app is opened for processing. After the processing is done the callback function for the app was invoked after returning to foreground and pushViewController was getting proper viewContoller in iOS12. But due to increase in processing speed and multi threading the callback function for the app was not called in required sequence, instead viewWillEnterForeground() was called which must be the default correct order and was calling pushViewController which was null. Thus moved some callback logic into viewWillEnterForeground() function and now it is working for iOS13 and iOS12 and bellow.