24

I'm getting an assertion failure while scrolling a picker view w/ zero data(zero rows). While scrolling the picker view I'm getting this crash. Testing on iOS 6

* Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit_Sim/UIKit-2372/UITableViewRowData.m:1630

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path ( 2 indexes [0, 0])'

Any help is appreciable.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Manoj
  • 953
  • 2
  • 8
  • 24
  • 1
    This actually just showed up for me when everyone started updating to iOS6. I had zero crashes related to this before the iOS release. – iwasrobbed Oct 11 '12 at 11:06
  • I can confirm this is iOS 6 only. iOS 5 does not crash with an empty picker view. – Vinnie Nov 05 '12 at 16:09
  • Phew. Aha.. I wondered why our app suddenly started crashing all over the place. Thanks above commenters for noticing! – Kalle Nov 13 '12 at 22:19

2 Answers2

39

I've the same problem

I don't know reason why it is happen,

but it can be fixed in ios6 (how it works in ios5 I didn't check):

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if ([self getCount] == 0)
        return 1;
     return [self getCount];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:   (NSInteger)component reusingView:(UIView *)view {
   if ([self getCount] == 0)
       return nil;
}
INT
  • 406
  • 4
  • 2
0

The answer is actually very simple! After having some trouble with this myself, I discovered that you must set the delegate and the dataSource to the view controller that the picker view is connected to.