代码之家  ›  专栏  ›  技术社区  ›  user278859

如何在没有计时器变量的情况下调用scheduledTimerWithTimeInterval

  •  -2
  • user278859  · 技术社区  · 6 年前

    希望删除计时器未在中使用的警告…

     timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(loadSeries:) userInfo:_response repeats: NO];
    

    我找到一个建议使用…

     NSTimer.scheduledTimerWithTimeInterval(timeInterval: 0.1, target: self, selector: @selector(loadSeries:), userInfo: _response, repeats: false)
    

    但是,它返回的错误是nstimer没有scheduledTimerWithTimeInterval属性,并且该目标未声明。

    找不到任何方法来创建没有悬空计时器变量的计时器。

    谢谢,

    约翰

    1 回复  |  直到 6 年前
        1
  •  1
  •   matt    6 年前

    而不是

    timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(loadSeries:) userInfo:_response repeats: NO];
    

    …只需删除分配。

    [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(loadSeries:) userInfo:_response repeats: NO];