0
我正在创建一个统计信息页面,显示使用某个项目的次数。如果该行的数组为空,则隐藏单独的行
每行有一个itemTitle
和itemCount
。 并非每个itemTitle都有数据(如果用户未填充该数据,但每行都会有itemCount)。
我想隐藏空行。
这是我正在尝试的,但是当这是真的,它隐藏所有行,而不是单个空行。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: "StatsCell", for: indexPath)
let itemTitle: UILabel = cell.viewWithTag(1000) as! UILabel
let itemCount: UILabel = cell.viewWithTag(1001) as! UILabel
itemTitle.text = self.statsArray[(indexPath as NSIndexPath).row].itemTitle
itemCount.text = "\(self.statsArray[(indexPath as NSIndexPath).row].itemCount)"
if (self.statsArray[(indexPath as NSIndexPath).row].itemTitle).isEmpty {
tableView.rowHeight = 0
}
return cell
}
见附件中的例子
感谢
谢谢瑜珈。请注意,你的代码不是swift 3.请修改为:覆盖func tableView(_ tableView:UITableView,heightForRowAt indexPath:IndexPath) - > CGFloat因此,未来的用户将受益 –
哦,是的。感谢您指点。完成 – Yogi