开发者

How do I use selectedRowInComponent method for UIPickerView

开发者 https://www.devze.com 2023-01-08 16:57 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消