定时器(NSTimer)

2016-07-19  本文已影响15人  nalis风

NSTimer的cheduledTimerWithTimeInterval:invocation:repeats:或scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:类创建NSTimer对象

调用该类方法时。需要传入以下参数:

1.timeInterval:指定每个多少秒执行一次任务

2.invocation 或target与selector:指定冲扶持性的任务 入股欧威target 和selector参数:指定某个对象的特定方法

invocation-传入一个NSInvocation,为target和selector的封装

3.userInfo:传入额外的附加信息

4.repeats:该参数需要之定义BOOL值,该参数控制是否需要重复执行任务

销毁定时器 使用invalidate方法

FKPreson* p=[[FKPreson alloc]init];

p.address=@"123123123";

p.count=0;

[NSTimer scheduledTimerWithTimeInterval:0.5 target:p selector:@selector(showAddress:) userInfo:nil repeats:YES];

-(void)showAddress:(NSTimer*)timer{

NSLog(@"%@",self.address);

self.count++;

if (count>10) {

NSLog(@"取消计时器");

[timer invalidate];

}

}

7.3对象复制

上一篇下一篇

猜你喜欢

热点阅读