美文网首页
iOS-主线程操作UI(对UI进行更新只能在主线程进行)

iOS-主线程操作UI(对UI进行更新只能在主线程进行)

作者: 守护浪漫的小香樟 | 来源:发表于2016-12-05 12:00 被阅读0次

 方法一:

// waitUntilDone:是否线程任务完成执行

[self performSelectorOnMainThread:@selector(updateImage:) withObject:data waitUntilDone:YES];

方法二:

dispatch_async(dispatch_get_main_queue(), ^{

//更新UI的代码,不用主线程中调用

});

方法三:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

NSLog(@"线程2:%@",[NSThread currentThread]);

}];

相关文章

网友评论

      本文标题:iOS-主线程操作UI(对UI进行更新只能在主线程进行)

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