您好,我有 TableView 从 API 获取数据
但我想显示具有特殊条件的行
我试图隐藏我不想要的行,但我不想在单元格中显示它们
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: DetailsListCell = tableView.dequeueReusableCell(at: indexPath)
switch self.type!{
case "inbox":
if inboxData[indexPath.row].delYn != "Y"{
cell.configure(withDate: inboxData[indexPath.row].dodate, withName: inboxData[indexPath.row].deptNm, withMsgNameBottom: inboxData[indexPath.row].title)
}else{
cell.isHidden = true
}
最佳答案
您不应该在此方法中隐藏单元格。相反,您应该有一个数据模型或一些指示器,它应该告诉 TableView 要显示哪些行以及要隐藏哪些行。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3 // only the number of rows to show
}
关于ios - 如何在 Swift 中隐藏/删除空 TableView 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819579/