本文介绍了iOS使用NSTimers向选择器发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过NSTimer向选择器发送参数?
Is there a way to send a parameter to the selector via a NSTimer ?
myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:nil repeats:NO];
- (void)removeTheNote:(NSString*)note
{
NSLog(@"Note %@ ----------- REMOVED!",note);
}
我知道使用:
myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:myNote) userInfo:nil repeats:NO];
不起作用,所以我问,有办法吗?
doesn't work, so I am asking, is there a way to do this?
推荐答案
您可以为此使用userInfo
参数:
myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:myNote repeats:NO];
但是您将必须如下修改removeTheNote
:
But you will have to modify removeTheNote
as follows:
- (void)removeTheNote:(NSTimer *)timer
{
NSString *note = timer.userInfo;
NSLog(@"%@", note);
}
这篇关于iOS使用NSTimers向选择器发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!