I've got a cell that I've made a subclass for and am setting up all the layout stuff in the storyboard. On runtime, the cells are way shorter than I have them set to be in the storyboard.
I'm getting a different background color and height in the simulator.
class FeedCell: UITableViewCell {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var emailLabel: UILabel!
@IBOutlet weak var messageLabel: UILabel!
func configureCell(profileImage : UIImage, email : String, content : String) {
self.profileImage.image = profileImage
self.emailLabel.text = email
self.messageLabel.text = content
}
override func awakeFromNib() {
super.awakeFromNib()
}
}
That's the only code I've got in my subclass.
Any ideas?
Set proper constraint to table cell and set table view dynamic height using estimatedRowHeight
and rowHeight
eg
tableView.estimatedRowHeight = 120
tableView.rowHeight = UITableViewAutomaticDimension
When you create self-sizing table view cell (dynamic row height), use proper constraints to define cell's size and set the below properties ( rowHeight , estimatedRowHeight ) inside viewDidLoad
method.
override func viewDidLoad() {
super.viewDidLoad()
self.yourTableView.rowHeight = UITableViewAutomaticDimension
self.yourTableView.estimatedRowHeight = 130
}
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.