问题描述
我需要隐藏一个 UITableViewCell.我将 backgroundColor 设置为 clear,但单元格仍然可见.请看截图.
I need hide a UITableViewCell. I set backgroundColor to clear, but cell still visible. Please see the screenshot.
cell.backgroundColor = [UIColor clearColor];
推荐答案
通常情况下,您不会以这种方式隐藏它.相反,您应该尝试根本不显示它.在您的表视图控制器的 numberOfRowsInSection 方法中,尝试如下操作:
Normally, you wouldn't hide it this way. Rather, you should try not displaying it at all. In your table view controller's numberOfRowsInSection method, try something like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//... code regarding other sections goes here
if (section == 1) { // "1" is the section I want to hide
if (self.cellShouldBeVisible) {
return 0; // show no cells
} else {
return 1; // show one cell
}
}
}
(当然你可以用你自己的代码替换 self.cellShouldBeVisible)
(you can replace self.cellShouldBeVisible with your own code of course)
如果您想从显示单元格变为不显示单元格,请将 self.cellShouldBeVisible 设置为所需的 BOOL 值并调用 [self.tableView reloadData];
If you want to go from displaying to not displaying the cell, set self.cellShouldBeVisible to the desired BOOL value and call [self.tableView reloadData];
这篇关于如何隐藏 UITableViewCell?请看截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!