I have a label and an image.
if image != nil {
cell height = 445
} else {
//how do i set the cell height according to the label?
}
I have a label and an image.
if image != nil {
cell height = 445
} else {
//how do i set the cell height according to the label?
}
You should set the height of tableView cells in heightForRowAt
. This function returns the height of the cell for a given indexPath (as you probably have guessed). Inside there you can use return label.frame.height
In Swift 3:
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if image != nil {
return 445
} else {
return label.frame.height
}
}
Edit: You can't use cellForRowAt
until cells are initialized in cellForRowAt
. So Try this instead. It assumes the image and label are @IBOutlets