tags:

views:

37

answers:

2

I need to add a Pause/Wait function to my iphone objective-c app. The function sleep() doesn't work for me.

Need to Add Pause/Wait Funtion between both of these.

myscore += [self getcard];

myscore += [self getcard];

+2  A: 

I haven't seen such a function for objective-c, but I have used an NSTimer which calls a given function in a time-interval that you decide.

http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSTimer_Class/Reference/NSTimer.html

More specifically using the function scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: does it for me. Time interval is in seconds the "sleep" time between each tick, target is the class holding the function that should be called, selector the function.

scheduledTimerWithTimeInterval:1          // Ticks once per second
                        target:myObject   // Contains the function you want to call
                      selector:@selector(myFunction:) 
                      userInfo:nil
                       repeats:YES
Accatyyc
A: 

If you separate the code for what happens after the wait, you can use performSelector:withObject:afterDelay: to call that selector after a delay.

Example, quit the application after 5 seconds:

[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:5.0];
BarrettJ