2016-03-20 19 views
0

UITableViewのフッターとして使用しているカスタムUITableViewCellがあります。uitableviewフッターを動的に変更する

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    let cell = tableView.dequeueReusableCellWithIdentifier("footerCommentCell") as! FooterCommentTableViewCell 
    cell.footerIndex = section 
    cell.delegate = self 
    return cell 
} 

このフッターが有する自動レイアウトhttp://joxi.ru/DrloGbpC4Eb3vA など - 図1 2 - 図2 3 - INIT相view2Heightで図2の高さ制約(view2Height

0であり、そしていくつかのアクションのIこの制約定数を別の値、例えば-50に変更し、私のヘッダーをに変更したい。

これを実装する方法はありますか?

答えて

0

要件およびリロード表のセクションに基づいて、heightForFooterInSectionをオーバーライドし、0または50を戻すことができます。

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 

     //return value based on condition 
    } 
+0

私は、自動レイアウトを使用しているため、私が欲しい結果が得られません。私はこの方法で私のフッターセルへのアクセスを得ることができないので、私は、全体の高さを変える制約 を変更することはできません –

0

これは非常に簡単です。あなたが動的なことを言うときは、それを変更するための条件が必要であることを意味します。 例: 2つのUITableviewCellsをサブクラス化してから、テーブルビューをリロードしてください。

0

@ 2ank3thの回答に追加すると、フッターのセル/ビューを取得できます。

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    let footerView = tableView.footerViewForSection(0) as! FooterCommentTableViewCell 
// Your section number. (0 for understanding purpose) 

// Then you can modify the height constraint and return the height of footer here. 

} 
0
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
{ 
    return UITableViewAutomaticDimension 
} 

func tableView(tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat 
{ 
    return 44.0 
} 
関連する問題