iOS某操作霸占主线程过久导致界面假死的一种解决方法
2015-12-02 16:14
381 查看
转载请注明出处:iOS某操作霸占主线程过久导致界面假死的一种解决方法
- 博客园
记得结束后,把observer从nsnotificationcenter 中remover掉
- 博客园
/*首先往消息中心注册一个检测针对的observer。*/ [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(handleresult:) name:@"postno." object:nil]; /*然后创建一个线程做之前耗时过久的操作。*/ [nsthread detachnewthreadselecto:@selector(calculate) totarget:self withobject:nil]; /*耗时的操作*/ - (void)caculate { /*新建的线程必须创建自己的内存释放池!*/ nsautoreleasepool *pool = [[nsautoreleasepool alloc] init]; nsstring *result = @"1111"; /*事情做完后告知消息中心*/ [[nsnotificationcenter defaultcenter] postnotificationname:"postno." object:result]; [pool release]; } /*耗时操作执行完后的回调函数*/ - (void)handleresult:(nsnotification *)noti { id obj = [noti object]; [self performselectoronmainthread:@selector(getresult:) withobject:obj waitutildone:yes]; } /*在主线程进行的操作*/ - (void)getresult:(id)result { //do some thing(更新ui界面之类的) }
记得结束后,把observer从nsnotificationcenter 中remover掉
相关文章推荐
- ios 基本图形的绘制
- iOS通知的添加和移除
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
- iOS基础知识点
- IOS基础——图片浏览器
- iOS中如何获取image.xcassets中的启动图片
- IOS_图片轮播器实现
- IOS 图片拉伸技巧
- Ios上任意控件上添加自定义Badge
- 10个提升iOS开发效率的必用工具
- iOS提交程序时出现ITMS-90046错误的解决方式
- iOS 游戏渠道SDK 抽象工程封装(下)
- iOS错误汇总 Implicit declaration of function - C99 完美解决
- 151202iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- ios解决输入框弹出后position:fixed失效问题
- iOS应用程序间跳转总结
- hairline!ios实现边框0.5px
- iOS高级开发——CollectionView修改cell的文本及模型重构
- iOS 对于服务器下发数据的判断
- IOS开发调用系统相机和打开闪光灯