gpt4 book ai didi

swift - heightForHeaderInSection 什么时候被调用

转载 作者:行者123 更新时间:2023-11-28 16:10:15 24 4
gpt4 key购买 nike

我正在调用以下函数来更新 tableView。但是,我发现 heightForHeaderInSection 对于表中的每个部分都被调用了两次。因此,如果我有 5 个部分,该函数将被调用 10 次。这正常吗?

    tableView.beginUpdates()
let sections = NSIndexSet(index:posts.count - 1)
tableView.insertSections(sections, withRowAnimation: .None)
tableView.endUpdates()

最佳答案

要回答您的问题,让我们看看 UITableViewDelegate。来自 Apple 文档:

The delegate of a UITableView object must adopt the UITableViewDelegate protocol. Optional methods of the protocol allow the delegate to manage selections, configure section headings and footers, help to delete and reorder cells, and perform other actions.

那么在您的情况下何时调用 UITableViewDelegate?当您使用 insertSections 更新 tableView 时,将调用 Delegate。所以 heightForHeaderInSection 在你插入新的部分到 tableView 之后被调用。

heightForHeaderInSection 被调用的次数取决于您更新 tableView 的方式。

另外可以强调的是,Apple 没有给出明确的解释 UIKit 多久会调用你的委托(delegate)方法。

关于swift - heightForHeaderInSection 什么时候被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39658068/

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