lab12
lab12

Reputation: 6448

Timing? - cocoa

How would I be able to use timers? For example I want to show a certain text for 10 seconds and then I want to show a different text for the rest of the duration.

Thanks,

Kevin

Upvotes: 0

Views: 343

Answers (3)

Peter N Lewis
Peter N Lewis

Reputation: 17811

The easiest way to defer an action is to use NSObject's performSelector:withObject:afterDelay:

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay

Set your text the first time (or at init time) and then do something like:

[self performSelector:@selector(changeText) withObject:nil afterDelay:10.0];

You can cancel the request with:

+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument

which you will need to do if you want your object to be deallocated as performSelector retains both your object and the withObject parameter.

Upvotes: 5

mk12
mk12

Reputation: 26404

NSTimer documentation.

Upvotes: 1

Rob Napier
Rob Napier

Reputation: 299455

Start with the Timer Programming Topics for Cocoa.

Upvotes: 2

Related Questions