gpt4 book ai didi

ios - UITableViewAutomaticDimension 在滚动之前不工作

转载 作者:IT王子 更新时间:2023-10-29 05:08:21 25 4
gpt4 key购买 nike

首次加载 TableView 时,所有可见单元格都是估计的行高。当我向下滚动时,单元格会自动调整大小,当我向上滚动时,最初 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
}

关于如何让单元格最初自动调整大小的想法?

更新:从 Xcode 7 beta 6 开始,这不再是问题

最佳答案

只需在您的表格加载后调用“reloadSections”:

self.tableView.reloadSections(NSIndexSet(indexesInRange: NSMakeRange(0, self.tableView.numberOfSections())), withRowAnimation: .None)

或者在 Swift 3 中:

let range = Range(uncheckedBounds: (lower: 0, upper: self.tableView.numberOfSections))
self.tableView.reloadSections(IndexSet(integersIn: range), with: .none)

关于ios - UITableViewAutomaticDimension 在滚动之前不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27842764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com