Reference :
https://stackoverflow.com/a/14741253/1749293
Like the link above said , but it seems that it doesn't explain the reason.
In my code, the following will work :
dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector: @selector(helloWorld) withObject:nil afterDelay:0.5];
});
but, when i comment something like this , (and I really sure that I run it in the main thread!!)the code doesn't work :
// dispatch_async(dispatch_get_main_queue(), ^{
[self performSelector: @selector(helloWorld) withObject:nil afterDelay: 0.5];
// });
Can somebody tell me why ? AND ' self ', will nerver release/deallocated , i retain it until the application is over.
" Not Working " , means that , (no crash) it doesn't jump into "helloWorld" method :
-(void) helloWorld {
NSLog(@"hello world"); // I set a break point here for debug , it wouldn't pause forever
}
I think is the Run Loop cause this problem . Like this link said , but i need more details or more explicit explain.
When I had this kind of thing happen, I was calling performSelector from a GCD dispatch. So it was setting the timer in the GCD worker thread which went away before the timer fired. When GCD removed the worker thread, the timer was lost, so the selector was never called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With