开发者

Unselected UIPickerView value

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 s开发者_运维问答elected."

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜