我正在尝试找到最好的方法来保存我的应用程序的用户查看每个 UITableViewCell 的时间,以用于优化和度量目的。我还没有找到可以监控它的工具(Parse、AppSee 等),所以我手动进行。问题是,它的效率非常低。
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
UITableView *tableView = self.tableView; // Or however you get your table view
NSArray *paths = [tableView indexPathsForVisibleRows];
// For getting the cells themselves
NSMutableSet *visibleCells = [[NSMutableSet alloc] init];
for (NSIndexPath *path in paths) {
NSLog(@"visible: %i", path.row);
[visibleCells addObject:[tableView cellForRowAtIndexPath:path]];
}
}
然后,我将在不可见时立即启动 NSTimer,并在不再可见时停止它。
这有许多缺陷:
我的解决方案显然不是最优的。有更好的方法吗?欢迎您的解决方案
最佳答案
使用 TableView 委托(delegate)方法和 View Controller 显示方法。具体来说:
tableView:willDisplayCell:forRowAtIndexPath:
tableView:didEndDisplayingCell:forRowAtIndexPath:
viewDidDisappear:
关于ios - 监控 UITableViewCell 在屏幕上显示多长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21736351/