本文介紹了如何通過選擇器方法傳遞 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 值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!