2017-07-18 1 views
0

アイテムが使用された回数を表示する統計ページを作成しています。その行の配列が空の場合、個々の行を非表示にする

各行はitemTitleitemCountです。 すべての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として、高さを返すべき添付の例に

enter image description here

おかげ

答えて

1

を参照してください。それ以外の場合は通常の高さを返します。

+1

ありがとう。あなたのコードは迅速ではないことに注意してください3.次のように変更してください:func tableView(_ tableView:UITableView、heightForRowAt indexPath:IndexPath) - > CGFloat将来のユーザーには利益が得られるように –

+0

ああ。指してくれてありがとう。完了 – Yogi

関連する問題