我想从我的选择器方法中传递一个 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 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!