Right now I'm sleeping my main thread in order to have my application pause before running an action. [NSThread sleepForTimeInterval:0.75];
. I know that that is less than ideal from a programming perspective, what other options do I have?
Asked
Active
Viewed 1,489 times
1

Peter Kazazes
- 3,600
- 7
- 31
- 60
-
You want to block the whole app or is it to do an action after some delay? – Deepak Danduprolu Jun 16 '11 at 22:25
2 Answers
4
You could call the selector after a delay.
[self performSelector:@selector(yourAction:) withObject:nil afterDelay:0.75];

Paul Tiarks
- 1,881
- 1
- 13
- 10
-
1There is also NSTimer, but performSelector:withObject:afterDelay: is usually the way to go. +1 – Dancreek Jun 16 '11 at 22:58
3
For applications targeted for devices with iOS 4.0 or greater you could use Grand Central Dispatch:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, SecondsToWait*NSEC_PER_SEC), dispatch_get_current_queue(), ^{
// And Call Your Action Here.
});

Paul N
- 1,901
- 1
- 22
- 32