NSTimer 解析
iphone为我们提供了一个很强大得时间定时器 NSTimer
他可以完成任何定时功能:
我们使用起来也很简单,只要记住三要素就可以,具体得三要素是:时间间隔NSTimeInterval浮点型,事件代理
delegate和事件处理方法@selector();就可以用
+ (NSTimer *)scheduledTimerWithTimeIn
下面我写了一个很简单得例子
NSTimer *animateTimer;//定义一个类的成员变量
//初始化成员变量的值,启动Selctor()中调用的函数是可以有参数的,如果有参数,定义函数的时候记住别丢掉这个函数
animateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showAlert1) userInfo:nil repeats:YES];
//调用Fire成员函数,启动定时器
[animateTimer fire];
//NSTimer调用所响应的函数
-(void)showAlert1
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"message"
message:@"love you "
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
THE END !