EXC_BAD_ACCESS(code=2,address=0xb00000c等异常解决

一般都是没有在主线程进行UI界面刷新造成的。

建议界面刷新放到主线程:

1、dispatch_async主线程操作:

dispatch_async(dispatch_get_main_queue(), ^{

//更新UI操作

//.....

});

2、dispatch_async函数是异步操作:

dispatch_async(dispatch_get_global_queue(0, 0), ^{

// 处理耗时操作的代码块...

//通知主线程刷新

dispatch_async(dispatch_get_main_queue(), ^{

//回调或者说是通知主线程刷新});

});

3、performSelectorOnMainThread:

-(void)setupThread:(NSArray*)userInfor{

[NSThread detachNewThreadSelector:@selector(threadFunc:) toTarget:self withObject:(id)userInfor];

}

- (void)threadFunc:(id)userInfor{

NSAutoreleasePool*pool = [[NSAutoreleasePool alloc] init];

//。。。。需要做的处理。

//这里线程结束后立即返回

[self performSelectorOnMainThread:@selector(endThread) withObject:nil waitUntilDone:NO];

[pool release];

}

你可能感兴趣的:(EXC_BAD_ACCESS(code=2,address=0xb00000c等异常解决)