如何通过选择器方法传递 int 值? [英] how can i pass an int value through a selector method?

查看:23
本文介绍了如何通过选择器方法传递 int 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的选择器方法中传递一个 int 值,但是选择器方法只接受一个对象类型参数.

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];

方法执行到这里

-(int)tabledata:(int)cellnumber {
   NSLog(@"cellnumber: %@",cellnumber);
   idLabel.text = [NSString stringWithFormat:@"Order Id: %@",[[records objectAtIndex:cellnumber] objectAtIndex:0]];
}

但我在我的方法中没有得到精确的整数值,我只得到了 id 值.

but I am not getting exact integer value in my method, I am only getting the id value.

推荐答案

如果您拥有"目标选择器,最简单的解决方案是将 int 参数包装在 NSNumber 中:

The easiest solution, if you 'own' the target selector, is to wrap the int argument in an NSNumber:

-(int)tabledata:(NSNumber *)_cellnumber {
    int cellnumber = [_cellnumber intValue];
    ....
}

要调用此方法,您将使用:

To call this method you would use:

[self performselector:@selector(tabledata:) withObject:[NSNumber numberWithInt:y] afterDelay:0.1];

这篇关于如何通过选择器方法传递 int 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆