美文网首页
NSObject类 多线程

NSObject类 多线程

作者: 笑熬齊澄 | 来源:发表于2017-12-11 19:12 被阅读4次

//创建一个线程在子线程执行,aSelector代表了新创建的线程,arg是传入的参数

[Object performSelectorInBackground:@selector(doSomething:) withObject:nil];

//实现方法

- (void) doSomething:(id)sender

{

//需要自行管理内存的释放

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

//执行你的代码

//回主线程更新UI

[selfperformSelectorOnMainThread:@selector(mainWork) withObject:nilwaitUntilDone:NO];

[pool release];

}

相关文章

网友评论

      本文标题:NSObject类 多线程

      本文链接:https://www.haomeiwen.com/subject/nklwixtx.html