Objective c 在NSTimer的userInfo中传递整数
我正试图通过Objective c 在NSTimer的userInfo中传递整数,objective-c,nstimer,nsinteger,Objective C,Nstimer,Nsinteger,我正试图通过NSTimer的userInfo字段传递一个整数(testInt) timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(count:) userInfo:testInt repeats:YES]; 但是,我收到一条不兼容类型的错误消息 有人知道如何将数字传递到计数方法吗?您需要将其框到: userInfo应该是一个对象。 timer = [NSTimer schedul
NSTimer的userInfo
字段传递一个整数(testInt
)
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(count:) userInfo:testInt repeats:YES];
但是,我收到一条不兼容类型的错误消息
有人知道如何将数字传递到计数方法吗?您需要将其框到:
userInfo
应该是一个对象。
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(count:)
userInfo:@(testInt) // <-- @() around your int.
repeats:YES];
int testInt = [timer.userInfo intValue];