How do I use selectedRowInComponent method for UIPickerView
I have a UIPickerView object that has five rows that a user can select. I want to return the index of the row that the user selects on IBAction. When my method is called, I can return the text of the v开发者_开发知识库alue of what the user selected with this code:
NSString * userChoice = [self pickerView:picker titleForRow:[picker selectedRowInComponent:0] forComponent:0];
I want to now return as an NSInteger, the row that is returned. The following code kills the program and I don't know why:
NSLog(@"hello?? %@", [picker selectedRowInComponent:0]);
Any thoughts?? Is there a better method to use besides selectedRowInComponent?
try this
NSLog(@"hello?? %d", [picker selectedRowInComponent:0]);
An NSInteger is not an object it's a typedef for a long or int (see doc).
As Aaron pointed out, you can use any of the format specifiers: %d, %D, %i
精彩评论