参考 :
https://stackoverflow.com/a/14741253/1749293
就像上面的链接说的那样,但似乎没有解释原因。
在我的代码中,以下将起作用:
dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector: @selector(helloWorld) withObject:nil afterDelay:0.5];
});
但是,当我评论这样的事情时,(我真的确定我在主线程中运行它!!)代码不起作用:
// dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector: @selector(helloWorld) withObject:nil afterDelay: 0.5];
// });
有人可以告诉我为什么吗?AND 'self',将神经释放/释放,我保留它直到应用程序结束。
“不工作”,意味着,(没有崩溃)它不会跳转到“helloWorld”方法:
-(void) helloWorld {
NSLog(@"hello world"); // I set a break point here for debug , it wouldn't pause forever
}
我认为是Run Loop导致了这个问题。就像这个链接说的那样,但我需要更多细节或更明确的解释。