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
?
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. 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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.