我试图通过testInt
的{{1}}字段传递整数(userInfo
)
NSTimer
但是我收到了不兼容的类型错误消息。
有谁知道如何将数字传递给timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(count:) userInfo:testInt repeats:YES];
方法?
答案 0 :(得分:5)
您需要将其设为NSNumber:
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(count:)
userInfo:@(testInt) // <-- @() around your int.
repeats:YES];
然后在-count:
int testInt = [timer.userInfo intValue];