How to call a method every x seconds in Objective-C using NSTimer?

前端 未结 4 1783
鱼传尺愫
鱼传尺愫 2020-12-24 14:12

I am using Objective-C, Xcode 4.5.1 and working on an app for the iPhone.

I have a method A in which I want to call another method B to do a series of calculations e

4条回答
  •  时光说笑
    2020-12-24 15:02

    If you look at your code and compared to the one below

    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self
    select:@selector(targetMethod:myVolumeMonitor()) userInfo:nil repeats:YES];
    

    self means that you are invoking a method in same instance of your class, in your example the method is myVolumeMonitor

    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self
    selector:@selector(MethodB) userInfo:nil repeats:YES];
    

    and you are good to go though

    method be should look like this

    - (void)MethodB:(NSTimer*)timer { 
    // do something
    }
    

提交回复
热议问题