gpt4 book ai didi

ios - reloadData 后未调用 cellForRowAtIndexPath

转载 作者:行者123 更新时间:2023-11-28 12:43:02 24 4
gpt4 key购买 nike

我有一个需要通过委托(delegate)调用更新的 TableView Controller 。我已经设置了数据源和委托(delegate),并且在 TableView 的初始加载时,一切都按预期工作。我有一个在数据源更新后调用的委托(delegate)方法。委托(delegate)调用 TableView Controller 类中的刷新方法,该类调用 .reloadData()

调用 reloadData 时,会调用 numberOfRowsInSection 并准确返回行数,但永远不会调用 cellForRowAtIndexPath。

在此特定情况下,numberOfRowsInSection 返回 2,因此应调用 cellForRowAtIndexPath 两次,但它被调用了零次。

在初始加载时一切正常。只有在调用 reloadData 时才会忽略 cellForRowAtIndexPath。我在 Obj-C 中做过很多次同样的事情,没有任何奇怪的地方。 Swift 中是否存在任何已知问题?

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier(LayerMenuCell.reuseId) as! LayerMenuCell
// ....
return cell
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print(layerEntries?.count)
return (layerEntries?.count)!
}

func refresh() {
self.layersTableView.reloadData()
}

谢谢!

最佳答案

尝试设置 UITableViewdelegatedataSource:

myTable.delegate = self
myTable.dataSource = self

关于ios - reloadData 后未调用 cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38961813/

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