I should want to play video in to the UITableView
top cell/row
. My problem is that. How to play video into a top visible row and how to recognised the top cell of the UITableView
, while we will scroll the UITableView
up and down.
Asked
Active
Viewed 3,218 times
3

Sankalap Yaduraj Singh
- 1,167
- 2
- 14
- 32
-
No, When the scrolling will stop. at the time who is cell on the top. – Sankalap Yaduraj Singh Oct 27 '15 at 05:51
-
You can know which cell is the topmost visible by the first element returned by `[tableView indexPathsForVisibleRows]`. – Raptor Oct 27 '15 at 05:52
-
@Raptor, there's no guarantee that the first element is the first visible row. – Jeff May 02 '19 at 09:53
-
@Jeff please elaborate. (well, this question is 4 years old, the context might not be valid anymore...) – Raptor May 03 '19 at 01:56
-
@Raptor, the documentation for `indexPathsForVisibleRows` and `visibleCells` makes no promise about the order of the elements in the returned array, so it's an unfounded assumption that the first element matches the top visible row. The method `indexPathForRowAtPoint` would be a better way to find the top row. – Jeff May 04 '19 at 04:14
2 Answers
2
An alternative maybe. Use - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
to load/initialize your video.
And in -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
check the top cell using indexPathsForVisibleRows
and play that video.

RoHaN
- 372
- 3
- 14
1
You can use UITableView
's -indexPathsForVisibleRows
or -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);
}
for additional reference

Community
- 1
- 1

Anbu.Karthik
- 82,064
- 23
- 174
- 143
-
I have used it. But it is not perfectly work for me. I want to play video like as Facebook scroll page. When we scroll page then video auto play – Sankalap Yaduraj Singh Oct 27 '15 at 05:57
-
1then you need to customize something like , when your scrolling is stop u get the current /top cell index on that time you need to play the video using web view or else and reload the current cell or reload entire cell, simple – Anbu.Karthik Oct 27 '15 at 05:59
-
@SankalapYadurajSingh -- any queries, when the scroll is stop on that time your cell contains video , customize the video frame and play using autoplay ,got it – Anbu.Karthik Oct 27 '15 at 06:18
-
-
@SankalapYadurajSingh -- see this link may be helps you http://stackoverflow.com/questions/19066713/how-to-play-video-autoplay-in-uitableview-cell, http://4byte.cn/question/467831/how-to-play-video-autoplay-in-uitableview-cell.html – Anbu.Karthik Oct 27 '15 at 06:24
-
@Anbu.Karthik While loading videos in scroll view delegates. Aren't there any chances that my tableview scroll gets stuck if I scroll continuosly? – RoHaN Oct 27 '15 at 06:30