3

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?

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
Gener Kill
  • 75
  • 2
  • 8
  • Could you paste your crash log? And `selectRow:inComponent:animated:` does work in iOS 6. – sunkehappy Nov 24 '12 at 04:18
  • Could you check if row #1 really exist? Usually crashing was due to an non-existing row or component. – John Nov 24 '12 at 07:57
  • @user1256663 Yes,I checked.Row & component is existing. – Gener Kill Nov 24 '12 at 09:20
  • @sunkehappy Crash log : "Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableIndexSet addIndexesInRange:]: Range {2147483647, 1} exceeds maximum index value of NSNotFound - 1'" – Gener Kill Nov 24 '12 at 09:23
  • 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 paste more **real** code. – sunkehappy Nov 24 '12 at 09:45
  • @sunkehappy [_pickerview selectRow:[arr objectAtIndex:i] inComponent:0 animated:NO]; – Gener Kill Nov 24 '12 at 10:05
  • More code please(update your question, don't add code by adding comment). I guess your `i` or `[arr objectAtIndex:i]` will give you a `-1`. – sunkehappy Nov 24 '12 at 10:11
  • @sunkehappy Problem solve.This is avulgar mistake.Sorry about that and thank you very much. – Gener Kill Nov 24 '12 at 12:51

3 Answers3

9

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: false)
João Vitor
  • 241
  • 5
  • 11
sunkehappy
  • 8,970
  • 5
  • 44
  • 65
1

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.

Gourav Joshi
  • 2,419
  • 2
  • 27
  • 45
0

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];

user1398739
  • 216
  • 5
  • 8