Expand and Collapse tableview cells

前端 未结 4 1181
面向向阳花
面向向阳花 2020-12-01 10:43

I\'m able to expand and collapse cells but i wanna call functions (expand and collapse) inside UITableViewCell to change button title.

import UIKit

clas         


        
4条回答
  •  庸人自扰
    2020-12-01 10:59

    All you need is implement UITableView Delegate this way:

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    
    override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    

    By default, estimatedHeight is CGRectZero, when you set some value for it, it enables autoresizing (the same situation with UICollectionView), you can do even also so:

    tableView?.estimatedRowHeight = CGSizeMake(50.f, 50.f); 
    

    Then you need to setup you constraints inside your cell.

    Check this post: https://www.hackingwithswift.com/read/32/2/automatically-resizing-uitableviewcells-with-dynamic-type-and-ns

    Hope it helps)

提交回复
热议问题