gpt4 book ai didi

ios - 为什么不会第二次调用 willDisplayCell

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:28:33 25 4
gpt4 key购买 nike

我有一个带表格的 View Controller 。第一次创建和呈现单元格时,将按顺序调用以下函数(除了 View Controller 函数):

....
func viewWillAppear(_ animated: Bool)

func cellForRow(at indexPath: IndexPath) -> UITableViewCell?

optional func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

func viewWillDisappear(_ animated: Bool)
....

当我退出屏幕时,调用了以下函数。

....
func viewWillAppear(_ animated: Bool)

func viewWillDisappear(_ animated: Bool)
....

但是为什么在viewWillAppearviewWillDisappear之间没有调用willDisplaycell呢?

日志是:

viewWillAppear
cellForRowAtIndexPath: 0
willDisplayCell: 0
cellForRowAtIndexPath: 1
willDisplayCell: 1
cellForRowAtIndexPath: 2
willDisplayCell: 2
viewWillDisappear
viewWillAppear
viewWillDisappear

代替:

viewWillAppear
cellForRowAtIndexPath: 0
willDisplayCell: 0
cellForRowAtIndexPath: 1
willDisplayCell: 1
cellForRowAtIndexPath: 2
willDisplayCell: 2
viewWillDisappear
viewWillAppear
willDisplayCell: 0
willDisplayCell: 1
willDisplayCell: 2
viewWillDisappear

最佳答案

我最终所做的是检查 viewDidAppear 中显示了哪些单元格。不确定这是最佳答案,所以请不要犹豫添加更好的答案。

-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

[self logVisibleSections];
}

-(void)logVisibleSections
{
for (NSIndexPath *indexPath in self.tableView.indexPathsForVisibleRows)
{
// Do what needs to be done with visible cells
}
}

关于ios - 为什么不会第二次调用 willDisplayCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52758794/

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