大家好,又见面了,我是你们的朋友全栈君。
使用 NSTimer scheduledTimerWithTimeInterval: target: selector:userInfo: repeats: 的时候有两个地方需要注意 。
举个例子:
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(sendBroadcast:)
userInfo:@"hello I'm the info to send"
repeats:NO];
// sendBroadcast的定义形式应该是
-(void)sendBroadcast: (NSTimer *)timer {
NSString *msg = (NSString *)[timer userInfo]; // [msg isEqualToString @"hello I'm the info to send"] == YES
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/154827.html原文链接:https://javaforall.cn