iOS presentViewController:animated:completion:延迟问题
2016-07-31 11:02
966 查看
iOS presentViewController:animated:completion:延迟问题
在 iOS 中,当使用- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion
方法进行界面跳转的时候,有时候会出现延迟,这个延迟有时候会有好几秒的时间才会执行 completion,有时候干脆就一直不会跳转。
例如:在tableview的点击方法中执行
DLAlertViewController *alertViewController = [[DLAlertViewController alloc] initWithNibName:nil bundle:nil]; ...... [self presentViewController:alertViewController animated:YES completion:^{ }];
alertViewController 跳转延迟很长时间,有时候干脆就不跳转了。但让人头疼的是点击cell的时候,在alertViewController跳转延迟过程中,滑动一下tableview或者再次点击一下cell,alertViewController会立即跳转。
查找了很长时间,总算得出一个原因:由于某种原因,presentViewController跳转时completion的内容并不会真的马上触发执行,除非有一个主线程事件触发这种消费。比如在弹出慢的时候,你随便点击一下屏幕,马上就能弹出来 。
所以得出相应的解决方法:
1.在主线程中执行跳转:
WS(weakSelf); dispatch_async(dispatch_get_main_queue(), ^{ DLAlertViewController *alertViewController = [[DLAlertViewController alloc] initWithNibName:nil bundle:nil]; ...... [weakSelf presentViewController:alertViewController animated:YES completion:^{ }]; });
2.在执行跳转前唤醒主线程。
/** WakeUpTheMainThread 方法什么都不执行,它的作用只是唤醒主线程 */ [self performSelectorOnMainThread:@selector(WakeUpTheMainThread) withObject:nil waitUntilDone:NO];
相关文章推荐
- IOS中的模态层presentViewController:animated:completion:
- IOS——使用PresentViewController推送页面,各页面间跳转及遇到的问题
- iOS 自定义presentViewController 动画时 出现的问题
- [self presentViewController:vc animated:YES completion:nil]的相互引用问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS 模态弹出 presentViewController弹出页面时有延迟
- iOS自定义TabBar使用popToRootViewControllerAnimated重叠问题解决
- iOS 关于presentViewController弹出页面反应迟钝的问题
- 解决presentViewController的延迟跳转问题
- ios中使用PresentModalViewController和dismissModalViewControllerAnimated的总结
- ios presentViewController:destinationView跳转后黑屏问题
- ios presentViewController:destinationView跳转后黑屏问题
- iOS之ViewController的多层presentViewController的dismiss问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS presentViewController的时候有卡顿或延迟
- 解决Swift中present(uiImagePickerController,animated: true,completion: nil)闪退的问题
- iOS开发-自定义TabBar使用popToRootViewControllerAnimated重叠问题解决
- iOS开发presentModalViewController ,若有UITextField,键盘无法下去的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- 因IOS版本导致的模态视图控制器dismissModalViewControllerAnimated调用问题