我有一个自定义的UITableViewCell,里面有一个UIPickerView。为了解决这个问题,我创建了一个Subclass,实现了UIPickerView委托和数据源方法。当我的cellForRowAtIndexPath实现这样的:自定义UITableViewCell中的UIPickerView
- (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)必须 等于 更新(0)之前在该部分中包含的行数,加上或减去从 插入或删除的行数(0插入,0删除)和正数或负数移动 行进入或退出该部分(0移入,0移出)。'
但是,如果我改变numberOfRowsInComponent:返回(在这个例子中7)的实际行数,一切工作就不错了。
我一直在尝试,但我没有看到发现问题/解决方案。任何帮助,将不胜感激。提前致谢!
编辑!正如@meda I推断的那样,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计数” %@”,[self.cellPickerInputArray计数]);'如果不是等于7您需要找出为什么 – meda
是的,已经尝试过了。请参阅上面的编辑。 – Marcal