Passing Data through NSTimer UserInfo

后端 未结 6 1998
抹茶落季
抹茶落季 2021-01-31 09:18

I am trying to pass data through userInfo for an NSTimer call. What is the best way to do this? I am trying to use an NSDictionary, this is simple enough when I have Objective-C

6条回答
  •  独厮守ぢ
    2021-01-31 10:02

    You may ask for the timer in the method given to the selector,

    Then you can grab useInfo from that timer (timer.userInfo):

    - (void)settingTimer
    {
    [NSTimer scheduledTimerWithTimeInterval:kYourTimeInterval
                                     target:self
                                   selector:@selector(timerFired:)
                                   userInfo:yourObject
                                    repeats:NO];
    }
    
    - (void)timerFired:(NSTimer*)theTimer
    {
      id yourObject = theTimer.userInfo;
      //your code here
    }
    

提交回复
热议问题