[英]Why willDisplayCell is not called the second time
I have a view controller with a table. 我有一个带表的视图控制器。 When a cell is created and presented the first time, the following functions are called in the order (in addition to view controller functions): 当第一次创建并呈现单元格时,将按顺序调用以下函数(除了视图控制器函数):
....
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)
....
When I exit the screen an, the following functions were called. 当我退出屏幕时,调用了以下功能。
....
func viewWillAppear(_ animated: Bool)
func viewWillDisappear(_ animated: Bool)
....
But why willDisplaycell
was not called between viewWillAppear
and viewWillDisappear
? 但是为什么在viewWillAppear
和viewWillDisappear
之间没有调用willDisplaycell
?
The logs are: 日志是:
viewWillAppear
cellForRowAtIndexPath: 0
willDisplayCell: 0
cellForRowAtIndexPath: 1
willDisplayCell: 1
cellForRowAtIndexPath: 2
willDisplayCell: 2
viewWillDisappear
viewWillAppear
viewWillDisappear
Instead of: 代替:
viewWillAppear
cellForRowAtIndexPath: 0
willDisplayCell: 0
cellForRowAtIndexPath: 1
willDisplayCell: 1
cellForRowAtIndexPath: 2
willDisplayCell: 2
viewWillDisappear
viewWillAppear
willDisplayCell: 0
willDisplayCell: 1
willDisplayCell: 2
viewWillDisappear
What I did eventually is checking what cells are presented in viewDidAppear. 我最终做的是检查viewDidAppear中显示的单元格。 Not sure it's the best answer, so don't hesitate to add better ones. 不确定这是最好的答案,所以不要犹豫,添加更好的答案。
-(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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.