iOS_某操作霸占主线程过久导致“界面假死”的一种解决方法
2013-07-29 19:53
537 查看
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html#//apple_ref/doc/uid/10000057i-CH1-SW1
记得结束后,把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某操作霸占主线程过久导致界面假死的一种解决方法
- 最简单解决c#在UI线程中执行耗时方法导致界面假死的方法
- 如何解决iOS界面操作导致导致NSTimer暂停计时的问题?
- 程序界面假死的一种解决方法 - 线程
- 最简单解决c#在UI线程中执行耗时方法导致界面假死的方法
- ios TableViewCell导致的界面错乱的解决方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios 调试技巧收藏 一 解决EXC_BAD_ACCESS错误的一种方法--NSZombieEnabled
- IOS-65-解决UIAlertView导致界面弹出键盘的问题
- winform 在mdi窗口重绘界面时,mdi挡住主窗体,导致鼠标拖动缩放窗体大小失效的解决方法随笔
- android4.0以上访问网络不能在主线程中进行以及在线程中操作UI的解决方法
- 费时操作界面无假死的BackgroundWorker方法
- IOS 自定义返回按钮 滑动返回假死解决方法
- IOS WebView修改contentInset 导致webview长按弹出菜单跳动的解决方法
- 由于某种错误导致数据表数据巨大(千万级别),删除后对该数据操作速度极慢的原因及解决方法
- 一个页面中使用多个iframe导致在ie中假死问题的解决方法
- winform频繁刷新导致界面闪烁解决方法
- ios UITableView中Cell重用机制导致内容重复解决方法
- IOS - No provisioning profiles with a valid signing identity 一种解决方法
- iOS开发发觉好多的界面上移了解决方法