对于某些人来说,这可能是一个简单的问题。对我来说很头疼。如何在此方法中将整数作为id对象发送:
[self performSelectorOnMainThread:@selector(requestImageAtIndex:) withObject:index waitUntilDone:NO];
索引是这里的整数。
提前谢谢大家。
P.S。 “没有愚蠢的问题,只有愚蠢的答案。” Marshall Loeb
答案 0 :(得分:1)
为什么不将它包装在NSNumber
对象中?
[self performSelectorOnMainThread:@selector(requestImageAtIndex:)
withObject:[NSNumber numberWithInteger:index]
waitUntilDone:NO];
答案 1 :(得分:0)
要在这种情况下传递普通值,您需要将它们包装到某些objective-c对象中。在您的情况下,NSNumber将起作用(当然requestImageAtIndex
方法必须将NSNumber
对象作为参数才能使其工作):
[self performSelectorOnMainThread:@selector(requestImageAtIndex:)
withObject:[NSNumber numberWithInt:index]
waitUntilDone:NO];
答案 2 :(得分:0)
int index;
index=5;
[self performSelectorOnMainThread:@selector(requestImageAtIndex:) withObject:[NSNumber numberWithInt:index] waitUntilDone:NO];
-(void)requestImageAtIndex:(NSNumber*)number{
int i=[number intValue];
}