因此,如果我理解正确,您更愿意使用 tableViewCells,在某些用户操作后(可能在按下同一单元格中的一个按钮之后)可以扩展部分 tableviewcell 吗?
那么你可以考虑在你的表格视图单元格中使用这样的方法
- (IBAction)action:(id)sender {
[_delegate actionPressed:relevantData];
}
操作连接到相应按钮的位置。
然后在你的 tableviewcontroller 中实现该方法
-(void)actionPressed:(id)relevantData
{
//update your datasource, for example retrieve the text you want in your expanded views
[self.tableView reloadData];
}
在方法中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//normal things about reusing cells etc.
[cell configureWithData:(id)Data];
return cell;
}
在您的自定义表格单元格中实现 configureWithData。根据要配置单元格的数据(这可能取决于是否按下了某些按钮),您可以设置单元格并扩展某些视图。
确保在
中考虑到这一点
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//return correct cell height depending on which views in cell were expanded or not
}
或者你可以用自动布局连接你的单元格并在 viewdidload 中使用类似的东西
self.tableView.estimatedRowHeight=100.0;
self.tableView.rowHeight=UITableViewAutomaticDimension;