UITableViewAutomaticDimension直到滚动才工作 [英] UITableViewAutomaticDimension not working until scroll
问题描述
首次加载表视图时,所有可见单元格都是estimatedRowHeight。当我向下滚动时,单元格会自动调整大小,当我向上滚动时,最初估计的单元格会自动调整大小。
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()
}
和
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?
更新:从Xcode 7 beta 6开始,这不再是一个问题
UPDATE: As of Xcode 7 beta 6 this is no longer an issue
推荐答案
我遇到了同样的问题,发现附件 cell.accessoryType
当它不是无
时会自动调整大小,所以它似乎是Xcode中的一个错误。
I ran into the same issue and found out that the accessory cell.accessoryType
messes with this automatic resizing when it is not None
, so it seems like a bug in Xcode at the moment.
但正如@Blankarsch所说,调用 reloadSections(..)
有助于解决此问题,如果你需要附件。
But as @Blankarsch mentioned, calling reloadSections(..)
helps to fix this issue if you need to have an accessory.
这篇关于UITableViewAutomaticDimension直到滚动才工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!