美文网首页
定时器(NSTimer)

定时器(NSTimer)

作者: nalis风 | 来源:发表于2016-07-19 11:27 被阅读15次

    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对象复制

    相关文章

      网友评论

          本文标题:定时器(NSTimer)

          本文链接:https://www.haomeiwen.com/subject/xiumjttx.html