【发布时间】:2023-04-09 08:13:01
【问题描述】:
我有办法
-(void)addFunction:(int)x andY:(int)y{
countdown--;
if(countdown == 0){
NSLog(@"Your time expired");
[myTimer invalidate];
}
else {
int c = 0;
c = x+y;
NSLog(@"%i",c);
}
}
-(void)RunTimer{
countdown = 5; //countdown has been declared as a static variable so the whole class can access it in its current state.
NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(addFunction: :) userInfo:nil repeats:YES];
}
现在我的问题是,addFunction 在我提供参数之前不会运行,否则它将打印 Null 值,我如何通过 NSTimer 调用具有参数的方法并发送这些参数?
【问题讨论】:
-
例如,您为什么不使用
userInfo?正是为了这个目的......
标签: ios