iOS_某操作霸占主线程过久导致“界面假死”的一种解决方法

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html#//apple_ref/doc/uid/10000057i-CH1-SW1

/*首先往消息中心注册一个检测针对的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掉