我在 grouptableview 中有一个自定义的 tableview 单元格。我有一个隐藏的。然后我必须让它可见。单元格标记为 3。
这不适用于我的代码:
if (self.tableView.tag == 3) {
self.tableView.hidden = NO; //Not working.
}
我只需要让一行可见。我希望你明白。
最佳答案
在 SWIFT 中,您需要做两件事,
隐藏您的手机。 (因为reusable cell可能会冲突)
将单元格高度设置为零。
看这里
隐藏您的手机。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let myCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellID",for: indexPath) as! UITableViewCell if(indexPath.row < 2){ myCell.isHidden = true }else{ myCell.isHidden = false } return myCell }
将单元格高度设置为零。
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { var rowHeight:CGFloat = 0.0 if(indexPath.row < 2){ rowHeight = 0.0 }else{ rowHeight = 55.0 //or whatever you like } return rowHeight }
使用它您可以消除可重复使用的单元格冲突问题。
您可以对 cell?.tag 执行相同的操作,也可以按标签隐藏特定的单元格。
关于ios - UITableView 设置 tableview 行隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386939/