【问题标题】:How to get a visible top row from the UITableView如何从 UITableView 中获取可见的顶行
【发布时间】:2015-10-27 05:48:08
【问题描述】:

我应该想在UITableView 顶部cell/row 中播放视频。我的问题是这样的。如何将视频播放到顶部可见行以及如何识别UITableView 的顶部单元格,同时我们将上下滚动UITableView

【问题讨论】:

  • 否,滚动何时停止。当时谁是最上面的单元格。
  • 您可以通过[tableView indexPathsForVisibleRows]返回的第一个元素知道哪个单元格是最顶部可见的。
  • @Raptor,不能保证第一个元素是第一个可见行。
  • @Jeff 请详细说明。 (嗯,这个问题已经 4 年了,上下文可能不再有效......)
  • @Raptor,indexPathsForVisibleRowsvisibleCells 的文档没有承诺返回数组中元素的顺序,因此第一个元素与顶部可见行匹配是没有根据的假设。方法indexPathForRowAtPoint 将是找到顶行的更好方法。

标签: ios swift uitableview uiscrollview avplayer


【解决方案1】:

也许是另一种选择。使用- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 加载/初始化您的视频。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中使用indexPathsForVisibleRows 检查顶部单元格并播放该视频。

【讨论】:

  • willDisplayCell 在 cellForRowAtIndexPath 之后被调用。
【解决方案2】:

您可以使用UITableView-indexPathsForVisibleRows-indexPathForRowAtPoint

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    NSIndexPath *topVisibleIndexPath = [[self.yourtableView indexPathsForVisibleRows] objectAtIndex:0];
    NSLog(@"top visible cell's section: %i, get row: %i", topVisibleIndexPath.section, topVisibleIndexPath.row);
}

更多reference

【讨论】:

  • 我用过。但这对我来说并不完美。我想像 Facebook 滚动页面一样播放视频。当我们滚动页面时,视频会自动播放
  • 那么您需要自定义类似的内容,当您的滚动停止时,您将获得当前的 /top 单元格索引,此时您需要使用网络视图播放视频,否则重新加载当前单元格或重新加载整个单元格,简单
  • @SankalapYadurajSingh - 任何查询,当滚动停止时,您的单元格包含视频,自定义视频帧并使用自动播放播放,明白了
  • 是的,我想做。
  • @SankalapYadurajSingh -- 看到这个链接可能对你有帮助 stackoverflow.com/questions/19066713/…, 4byte.cn/question/467831/…
猜你喜欢
  • 1970-01-01
  • 2011-10-10
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 2013-03-30
  • 2012-08-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多