问题
My application build & run in iOS 5.x perfectly, but it crashes when I call selectRow:inComponent:animated:
method of UIPickerView
in iOS 6.
code :
[_pickerview selectRow:1 inComponent:0 animated:NO];
I know this method is not work in iOS6 when I googled it, but I want to know other method to do this effect?
回答1:
Your crash log says you have used a -1
in code where should be a number in range {0, 1}. But in the the code you paste you indeed use 1
. So you need to check your parameter for your xxx
and yyy
[_pickerview selectRow:xxx inComponent:yyy animated:NO];
回答2:
The above answers are correct, However if the value of array is different with picker value then this error appeared.
Here is my code
I am initialize in this way:
amPmArray = [[NSMutableArray alloc] initWithObjects:@"AM",@"PM", nil];
and I set value in picker :[picker selectRow:[amPmArray indexOfObject:currentTimeAMPMString] inComponent:5 animated:NO];
and I always get lower case value in currentTimeAMPMString like 'am, pm', and my array does'nt contain this type of item, So that's why I got crashing error.
回答3:
After 3 day finding, I found if you are using picker to associate with textField. Plz no need to assign any text to textField. Reason when you use below text it means assigned test should exist within the array.
[self->pickerView selectRow:[self->dataArray indexOfObject:self->textField.text] inComponent:0 animated:NO];
Use this one.
[self->pickerView selectRow:[self->dataArray objectAtIndex:row] inComponent:0 animated:NO];
来源:https://stackoverflow.com/questions/13538118/uipickerview-selectrow-crash-in-ios-6