【发布时间】:2014-03-30 14:38:12
【问题描述】:
我有一个自定义的 UITableViewCell,里面有一个 UIPickerView。为了管理它,我创建了一个子类,我在其中实现了 UIPickerView 委托和数据源方法。当我这样实现的 cellForRowAtIndexPath 时:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==2) {
PickerCellTableViewCell *cell2=[tableView dequeueReusableCellWithIdentifier:@"pickerCell" forIndexPath:indexPath];
cell2.cellPickerInputArray=self.pickerArray;
return cell2;
}else{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell" forIndexPath:indexPath];
cell.textLabel.text=[[self.inputArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
return cell;
}
}
在子类 .m 文件中,我有以下内容:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [self.cellPickerInputArray count];
}
我有以下问题:如果我这样离开它,它会崩溃并且控制台会给我这个:
无效更新:第 0 节中的行数无效。 更新 (7) 后包含在现有节中的行必须是 等于该节之前包含的行数 update (0),加上或减去插入或删除的行数 该部分(0 插入,0 删除)和加或减的数量 移入或移出该部分的行(0 移入,0 移出)。'
但是,如果我更改 numberOfRowsInComponent: 以返回实际的行数(本例中为 7),一切正常。
我一直在尝试,但找不到问题/解决方案。任何帮助,将不胜感激。提前致谢!
编辑!正如@meda 所建议的,我 NSLoged NSLog(@"PickerInputArray count"%@",[self.cellPickerInputArray count]); pickerView numberOfRowsInComponent
这里:
2014-03-30 21:04:54.756 TestPickerOnTable[3498:60b] PickerInputArray count0
2014-03-30 21:04:54.757 TestPickerOnTable[3498:60b] PickerInputArray count0
2014-03-30 21:04:54.758 TestPickerOnTable[3498:60b] PickerInputArray count0
2014-03-30 21:04:54.758 TestPickerOnTable[3498:60b] PickerInputArray count0
2014-03-30 21:04:54.762 TestPickerOnTable[3498:60b] PickerInputArray count7
2014-03-30 21:04:54.765 TestPickerOnTable[3498:60b] PickerInputArray count7
2014-03-30 21:04:54.767 TestPickerOnTable[3498:60b] PickerInputArray count7
2014-03-30 21:04:54.770 TestPickerOnTable[3498:60b] PickerInputArray count7
2014-03-30 21:04:54.771 TestPickerOnTable[3498:60b] PickerInputArray count7
2014-03-30 21:04:54.771 TestPickerOnTable[3498:60b] PickerInputArray count7
【问题讨论】:
-
记录它
NSLog(@"PickerInputArray count"%@",[self.cellPickerInputArray count]);如果它不等于 7,你需要找出原因 -
是的,已经试过了。请参阅上面的编辑。
标签: xcode uitableview uipickerview uipickerviewdelegate