2017-05-14 10 views
0

UITableviewの残りの空き領域を埋めるフッタビューでUITableviewを作成しようとしています。しかし、キャッチは、細胞が様々な高さを有することである。動的高さセルを使用したUITableviewとフッタービューの埋め込み

私は、細胞がすべて静的な高さであれば、そこにいくつの細胞があるのか​​を数え、静的な高さでそれを掛けることができます。残念ながら、この場合は動作しません。

現在の解決策:

静的高さセルのための作業。

動的高さセルでは機能しません。意図の

private func adjustFooterHeight() { 
     if data.count == 0 { 
      footerView.frame.size.height = tableView.bounds.height 
     } 
     else { 
      //I use data.count instead of (data.count - 1) as I have the extra hidden cell, as pictured in image 2. 
      let bottomFrame = tableView.rectForRow(at: IndexPath(row: data.count, section: 0)) 
      let height = tableView.bounds.height - (bottomFrame.origin.y + bottomFrame.height - rowHeight) 
      footerView.frame.size.height = height < 0 ? 0 : height 
      tableView.reloadData() 
     } 
    } 

図:

enter image description here

+0

非常にカスタマイズされたビューで塗りつぶしたいのですか、またはTableViewの残りの部分を単色にしたいですか?例えば白? –

+0

私は特にビューにたくさんのコンテンツを持たせたくありませんが、テーブルビューのコンテンツをView Controllerフレームの下部に届かせる必要があります。テーブルビューには、画面のサイズを超える十分なセルがあれば、それは必要ありませんが、それまでは必要です。私はビューコントローラの上に隠されたテーブルビューの最初のセルを持っているので、このフッタビューを使ってテーブルビューをスクロール可能にしています。それは隠されたプルダウンアクションのようなものです。私はポストを1枚または2枚更新します。 – Connor

+0

コンテキストの画像は素晴らしいでしょう:) –

答えて

0

だから私はここで

がソリューションです...それを考え出しました。

private func adjustFooterHeight() { 

     //Get content height & calculate new footer height. 
     let cells = self.tableView.visibleCells 
     var height: CGFloat = 0 
     for i in 0..<cells.count { 
      height += cells[i].frame.height 
     } 
     height = self.tableView.bounds.height - ceil(height) 

     //If the footer's new height is negative, we make it 0, since we don't need footer anymore. 
     height = height > 0 ? height : 0 

     //Create the footer 
     let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: height)) 
     self.tableView.tableFooterView = footerView 
    } 
関連する問題