一般都是沒有在主線程進(jìn)行UI界面刷新造成的。
建議界面刷新放到主線程:
1、dispatch_async主線程操作:
dispatch_async(dispatch_get_main_queue(), ^{
//更新UI操作
//.....
});
2、dispatch_async函數(shù)是異步操作:
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 處理耗時(shí)操作的代碼塊...
//通知主線程刷新
dispatch_async(dispatch_get_main_queue(), ^{
//回調(diào)或者說是通知主線程刷新});
});
3、performSelectorOnMainThread:
-(void)setupThread:(NSArray*)userInfor{
[NSThread detachNewThreadSelector:@selector(threadFunc:) toTarget:self withObject:(id)userInfor];
}
- (void)threadFunc:(id)userInfor{
NSAutoreleasePool*pool = [[NSAutoreleasePool alloc] init];
//。。。。需要做的處理。
//這里線程結(jié)束后立即返回
[self performSelectorOnMainThread:@selector(endThread) withObject:nil waitUntilDone:NO];
[pool release];
}