在我的UITableViewController
中,我有两个custom cells
两个1st cell
包含UIButton
而2nd cell
包含UITextField
。
目前我只有一个UITableViewCell subclass
用于两个单元格。
我想知道为什么我没有收到任何错误,即cell1没有文本字段,反之亦然。
这也是一种正确的方法,或者我必须给两个单元格不同subclass
。
答案 0 :(得分:0)
您可以在TableView中拥有多个自定义单元格。在您的委托功能中,您将决定要显示哪个单元格以及哪些数据。
这样的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if([this cell should be of type 1])
{
cell = [tableView dequeueReusableCellWithIdentifier:@"CellType1" forIndexPath:indexPath];
[self configureCellType1];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:@"CellType2" forIndexPath:indexPath];
[self configureCellType2];
}
return cell;
}
如果您只想保留一个自定义类类型,请将单元格中的按钮和文本元素保留在一起,然后根据当前单元格的索引隐藏和取消隐藏。