简体   繁体   中英

How to detect which UITableViewCell is at the top of a UITableView

I have a view with a map and and list displayed at the same time. I would like the map to move when the user scrolls the list.

I was hoping for something like

(UITableView*)tableView didScrollTableViewCellToTop:(UITableViewCell *)cell

I haven't found something that will support this yet.

Thanks in advance

You can get all the visibleCells by running...

NSArray *cells = [self.tableView visibleCells];

This returns an array of UITableViewCells.

You can then find the one with the lowest indexPath.row value to find the top one.

Remember that the UITableView is simply a scroll-view. So you can get the offset of the scroll view and use the position to get the cell at that location:

NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: point];

To continuously monitor and change, implement a scroll-view-delegate and implement the scrollViewDidScroll method.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM