简体   繁体   中英

Creating 2 dynamic cell prototypes in my ios swift TableView with different heights

I have to create a UIView Table in swift with 2 prototype cells, each having different heights. My first cell will only have a label and a button in same line, so its height should not be too much. Where as second cell will be having a image, 4 labels etc. so I need height for this. Is there a way I can change the height of dynamic tableview cell in code or IB?

Thanks! 在此输入图像描述

Set your controller as delegate for your UITableView . Then implement the optional function

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == 0
      return 180
    else 
      return 40 }

could you use the function:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    // return height for each cell
}

sorry if I've misunderstood the question.

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

this is a method you can use to set the height of all your cell according to the indexpath that is a table view delegate method . set the height of cell it it programatically . if you want to set the height through Ui that you can set a static height for all the cell .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM