我已将我的视图控制器设置为我的 UIPickerView 的数据源和委托,它由 IBOutlet 连接。屏幕显示一个空的选择器视图,在滚动时会崩溃。从日志中,似乎没有调用委托和数据源方法:我错过了什么?
- (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";
}
错误是:
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