• GCD方法,通过向主线程队列发送一个block块,使block里的方法可以在主线程中执行。
dispatch_async(dispatch_get_main_queue(), ^{      
    //需要执行的方法
});
  • NSOperation 方法
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];  //主队列
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
	//需要执行的方法
}];
[mainQueue addOperation:operation];
  • NSThread 方法
[self performSelector:@selector(method) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES modes:nil];

[self performSelectorOnMainThread:@selector(method) withObject:nil waitUntilDone:YES];

[[NSThread mainThread] performSelector:@selector(method) withObject:nil];
  • RunLoop方法
[[NSRunLoop mainRunLoop] performSelector:@selector(method) withObject:nil];

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
相关资源
相似解决方案