iOS presentViewController:animated:completion:延迟问题
来源:互联网 发布:码云的独立域名 编辑:程序博客网 时间:2024/06/02 09:00
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];
0 0
- iOS presentViewController:animated:completion:延迟问题
- IOS中的模态层presentViewController:animated:completion:
- presentViewController:navigationController animated:YES completion:^(void)
- [self presentViewController:vc animated:YES completion:nil]的相互引用问题
- iOS presentViewController方式跳转延迟
- iOS presentViewController的时候有卡顿或延迟
- iOS 模态弹出 presentViewController弹出页面时有延迟
- ios presentViewController:destinationView跳转后黑屏问题
- ios presentViewController:destinationView跳转后黑屏问题
- 解决Swift中present(uiImagePickerController,animated: true,completion: nil)闪退的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS 自定义presentViewController 动画时 出现的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- iOS——presentViewController
- 页面跳转问题presentViewController
- LeetCode Generate Parentheses递归方法
- ECharts插件简单入门——柱状图
- 将C++代码编译成Matlab可以调用的.mexw文件(涉及多个.cpp文件的编译)
- Linux内核版本和系统启动过程以及具体内核移植和根文件系统的制作
- 字符串之最
- iOS presentViewController:animated:completion:延迟问题
- 定位(相对、绝对)、z-index
- Flask web表单
- 两种高性能I/O设计模式reactor与proactor
- Android Studio代码大小写提示
- JavaScript事件详解
- Android--手机外部SD卡存储
- easyui常用组件
- SDUT2128树结构练习——排序二叉树的中序遍历