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
}
あなたはあなたのコードでoverride func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
を実装し、データソースで空の配列を持つ行0として、高さを返すべき添付の例に
おかげ
ありがとう。あなたのコードは迅速ではないことに注意してください3.次のように変更してください:func tableView(_ tableView:UITableView、heightForRowAt indexPath:IndexPath) - > CGFloat将来のユーザーには利益が得られるように –
ああ。指してくれてありがとう。完了 – Yogi