a loop in own Thread
I want to show some picture with a waiting of 2sec before showing the other. So i tried to do it with the good old C99 : sleep(300) but the UI does not update.
The second thing I tried was: 1. create the method in his own thread
[NSThread detachNewThreadSelector:@selector(gameIt) toTar开发者_开发问答get:self withObject:nil];
Then sleep in the Method with:
[NSThread sleepForTimeInterval:1];
But the same problem, the UI does not update. What do I make wrong? Please help me. Thank you.
Anytime you sleep
on the main thread, you will stall the UI.
You may have some luck with NSThread's class method scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
. You'll have to keep some context so that each invocation of your method will know what to do, but this will not stall your UI and it will give you the 3 second (or whatever) interval you're looking for.
Run your processing on the background thread, but when you edit the UI you need to performSelectorOnMainThread
[view performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
精彩评论