When the Table View is first loaded, all of the visible cells are the estimatedRowHeight. As I scroll down, the cells are being automatically sized properly, and when I scroll back up the cells that were initially estimatedRowHeight are being automatically sized properly.
Once the cells are being automatically sized, they don't ever seem to go back to being the estimatedRowHeight.
override func viewDidLoad() { super.viewDidLoad() self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil) self.tableView.estimatedRowHeight = 80.0 self.tableView.rowHeight = UITableViewAutomaticDimension // Uncomment the following line to preserve selection between presentations // self.clearsSelectionOnViewWillAppear = false // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem() }
and
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellIdentifier = "Cell" let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as CustomTableViewCell // Configure the cell... let restaurant = restaurants[indexPath.row] cell.namelabel.text = restaurant.name cell.locationlabel.text = restaurant.location cell.typelabel.text = restaurant.type cell.thumbnailImageView.image = UIImage(named: restaurant.image) cell.thumbnailImageView.layer.cornerRadius = cell.thumbnailImageView.frame.size.width / 2 cell.thumbnailImageView.clipsToBounds = true cell.accessoryType = restaurant.isVisited ? .Checkmark : .None return cell }
Thoughts on how to have the cells autoresize initially?
UPDATE: As of Xcode 7 beta 6 this is no longer an issue
Just call "reloadSections" after your Table is loaded:
self.tableView.reloadSections(NSIndexSet(indexesInRange: NSMakeRange(0, self.tableView.numberOfSections())), withRowAnimation: .None)
Or in Swift 3:
let range = Range(uncheckedBounds: (lower: 0, upper: self.tableView.numberOfSections)) self.tableView.reloadSections(IndexSet(integersIn: range), with: .none)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With