Unselected UIPickerView value

Posted by morticae on Stack Overflow See other posts from Stack Overflow or by morticae
Published on 2010-03-15T23:42:10Z Indexed on 2010/03/15 23:49 UTC
Read the original article Hit count: 403

Filed under:
|
|
|

According to the documentation, if a UIPickerView has no selected value, the expected return from selectedRowInComponent: should be:

"A zero-indexed number identifying the selected row, or -1 if no row is selected."

However, if I check the value the very line after initializing one, its value is 0. Even if I then manually set it to -1, it still returns 0. I would like to be able to detect whether the user has chosen a value yet or not, without recording it in a local variable. Is this possible?

example:

UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 46.0, 320.0, 216.0)];
[picker selectRow:-1 inComponent:0 animated:NO];
NSLog(@"SELECTED %d", [picker selectedRowInComponent:0]);

expected output:
SELECTED -1

actual output:
SELECTED 0

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about objective-c