如何通过选择器方法传递 int 值?
我想从选择器方法传递一个 int
值,但选择器方法只接受一个对象类型参数。
int y =0;
[self performselector:@selector(tabledata:) withObject:y afterDelay:0.1];
方法执行在这里
-(int)tabledata:(int)cellnumber {
NSLog(@"cellnumber: %@",cellnumber);
idLabel.text = [NSString stringWithFormat:@"Order Id: %@",[[records objectAtIndex:cellnumber] objectAtIndex:0]];
}
,但我没有在我的方法中获得精确的整数值,我只获得 id 值。
I want to pass an int
value from my selector method, but the selector method takes only an object type parameter.
int y =0;
[self performselector:@selector(tabledata:) withObject:y afterDelay:0.1];
Method execution is here
-(int)tabledata:(int)cellnumber {
NSLog(@"cellnumber: %@",cellnumber);
idLabel.text = [NSString stringWithFormat:@"Order Id: %@",[[records objectAtIndex:cellnumber] objectAtIndex:0]];
}
but I am not getting exact integer value in my method, I am only getting the id value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您“拥有”目标选择器,最简单的解决方案是将 int 参数包装在 NSNumber 中:
要调用此方法,您将使用:
The easiest solution, if you 'own' the target selector, is to wrap the int argument in an NSNumber:
To call this method you would use:
这也适用于
int
参数,如果您无法更改要执行的选择器的签名,则该参数特别有用。This works also for an
int
parameter, which is especially useful, if you are unable to change the signature of the selector you want to perform.使用 NSTimer 代替 PerformSelector:withObject:afterDelay:,这样:
您可以在计时器块中传递您想要的任何内容。
Instead of your performSelector:withObject:afterDelay:, use an NSTimer, thusly:
You can pass whatever you want in the timer block.