Automatic cell size in Swift

Asked

Viewed 313 times

1

Hello, I have a project that has a tableview with custom cells, up to Swift 1.1 the method tableView.rowHeight = UITableViewAutomaticDimension in the viewDidLoad and the number of lines in 0, were already enough for my cells to adapt to the content of characters contained in them. But after Swift 1.2 they don’t fit in anymore, someone could shed some light on that?

1 answer

1


Also put the estimated size (Value that is realistic for your case, a general case just to "accelerate" the computation):

tableView.estimatedRowHeight = 100
tableView.estimatedRowHeight = UITableViewAutomaticDimension // Talvez isso funcione no momento não tenho como testar.

If the problem still persists implement these Uitableviewdelegate methods:

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


func tableView(tableView: UITableView!, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
    return UITableViewAutomaticDimension
}
  • Obg Otávio, deu certo inserindo somenta a linha... func tableView(tableView: UITableView!, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
 return UITableViewAutomaticDimension
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.