2009年8月26日 星期三

do something in the future

1. execute function in the future

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

ex: [self performSelector:@selector(sing:) withObject:nil afterDelay:1.4];


2. use timer

(NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;

ex: [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(test:) userInfo:nil repeats:YES];
note:
to delete timer, use invalidate method
ex:
-(void)test:(NSTimer*)timer
{
[timer invalidate];
}

沒有留言:

張貼留言