0

I've set my view controller as the datasource and delegate of my UIPickerView, which is connected by an IBOutlet. The screen shows an empty pickerview that crashes upon scrolling. From the logs, it appears that the delegate and datasource methods are not getting called: what am I missing?

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    NSLog(@"test");
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if ((!self.projectNames) || ([self.projectNames count] == 0)) {
        NSLog(@"no array");
        return 1;
    }
    NSLog(@"there is an array");
    return [self.projectNames count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component
{
    if (self.projectNames) {
        return [self.projectNames objectAtIndex:row];
    }
    return @"No Projects";
}

The error is:

2013-03-07 22:15:15.929 CamSquad[1128:907] *** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit/UIKit-2380.17/UITableViewRowData.m:1630
2013-03-07 22:15:15.932 CamSquad[1128:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x1d097e80> 2 indexes [0, 0])'
*** First throw call stack:
(0x344de2a3 0x3c33797f 0x344de15d 0x34db3ab7 0x36316ffb 0x36334919 0x3649ec63 0x3666e8ef 0x3640923b 0x364226ed 0x36403d89 0x363cb3f5 0x365b8a39 0x362ef82f 0x362ee293 0x362f91e7 0x362f8db3 0x362e6801 0x362e611b 0x37fda5a3 0x37fda1d3 0x344b3173 0x344b3117 0x344b1f99 0x34424ebd 0x34424d49 0x37fd92eb 0x3633a301 0x671d5 0x3c76eb20)
libc++abi.dylib: terminate called throwing an exception
2
  • You need to make your view controller (or whatever class implements the above methods) the picker view's dataSource and delegate. Did you do this in IB?
    – rmaddy
    Mar 8, 2013 at 4:04
  • Can't believe I missed that. Thanks Mar 9, 2013 at 1:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.