UINavigationController: presenting view controller while dismissing another controller is in progress on iPad

旧巷老猫 提交于 2019-12-04 14:59:29

You cannot present another view as long as the dismissing of your 1st view is not complete. The animation of dismissing view should be completed before presenting new view. So, either you can set its animation to NO while dismissing, or use performSelector:withObject:afterDelay: and present the next view after 2-3 seconds.

Hope this helps.

You've not posted enough code to really see what you're doing, but one approach to the problem of dismissing and pushing view controllers clashing in this way is to make a the pop+posh into a single atomic operation operation, rather then seqential operations.

You can do this by using the setViewControllers:animated: method on UINavigationController. This allows you to effectively remove one or more view controllers, and add one or more view controllers, all as one cohesive operation, with one seamless animation.

Here's a simple example:

[self.navigationController pushViewController:loginController];

// ... later on, when user login is validated:
NSMutableArray *viewControllers = 
    [self.navigationController.viewControllers copy];

[viewControllers removeLastObject];

[viewControllers addObject:[[MyNewViewController alloc] init]];

[self.navigationController setViewControllers:viewControllers animated:YES];

If you do things this way, your code will be more predictable, and will work across iPhone and iPad.

For more info, see the API docs.

Update

Since your problem involves a modal dialog on top, try using setViewControllers:animated:NO to change the nav controller stack underneath the modal login dialog before you dismiss the modal.

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