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。我们通过为其创建一个导出来识别目标单元格:
https://stackoverflow.com/questions/8260267/
相关文章:
iphone - iPhone 上 NSString 的 AES 加密
iphone - 如何获取 UIImage 并给它一个黑色边框?
objective-c - NSInteger 的 NSLog/printf 说明符?
objective-c - RootViewController 切换过渡动画
objective-c - 检测 NSString 是否包含...?
ios - SDK iOS 8.0 中的产品类型单元测试包需要代码签名
objective-c - 为什么在 iOS 中使用前导下划线重命名合成属性?