UITableView
设置为静态单元格。
是否可以通过编程方式隐藏某些单元格?
最佳答案
在 UITable 中隐藏静态单元格:
- 添加此方法:
在你的 UITableView Controller 委托(delegate)类中:
objective-C :
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if(cell == self.cellYouWantToHide)
return 0; //set the hidden cell's height to 0
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
swift :
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
var cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
if cell == self.cellYouWantToHide {
return 0
}
return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}
将为 UITable 中的每个单元格调用此方法。一旦它为您要隐藏的单元格调用它,我们将其高度设置为 0。我们通过为其创建一个导出来识别目标单元格:
- 在设计器中,为要隐藏的单元格创建一个导出。 一个这样的单元格的导出在上面称为“cellYouWantToHide”。
- 在 IB 中选中“剪辑 subview ”以查找要隐藏的单元格。 您要隐藏的单元格需要具有 ClipToBounds = YES。否则文字会堆积在 UITableView 中。
关于ios - UITableView 设置为静态单元格。是否可以以编程方式隐藏某些单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8260267/