views:

170

answers:

1

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
+1  A: 

I'm not sure, but I think it will return -1 only if the component requested doesn't actually have any rows in it. There's no way to not have a row selected in a UIPickerView. I mean, you could have an empty row at the top, or something, and that would be index 0, but there's no way to tell the UIPickerView to not select any of the rows.

Ed Marty
I suppose that's the answer, but I would argue that either the documentation or the code is broken. The docs seem to clearly indicate that it supports a "no selection" mode, and says nothing about this just meaning there are no rows.
DougW