我正在尝试根据我选择的单元格是用户屏幕上的第一个还是最后一个单元格来触发一些代码。我不是要捕获数据数组的索引值。只是屏幕上可见的单元格的索引值。我确信这会创建一个可见单元格数组。
NSArray *indexPathsForVisibleRows = [myTableView indexPathsForVisibleRows];
但是我一直在 try catch 基于该数组的索引值,但我一直走入死胡同。 我尝试使用 CGPoint 并对其进行转换,但我一直收到错误消息。任何见解都会很有帮助!
最佳答案
根据该方法返回值的文档:
An array of NSIndexPath objects each representing a row index and section index that together identify a visible row in the table view. Returns nil if no rows are visible.
从该方法返回的数组包含 NSIndexPaths
。
NSArray *indexPathsForVisibleRows = [myTableView indexPathsForVisibleRows];
for(NSIndexPath *eachIndexPath in indexPathsForVisibleRows)
{
NSInteger row = eachIndexPath.row;
NSInteger section = eachIndexPath.section;
UITableViewCell *cell = [myTableView cellForRowAtIndexPath:eachIndexPath];
if(cell.isSelected)
{
// this is our selected cell
}
}
关于ios - 捕获单元格的索引值,但仅来自屏幕上的可见单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24046390/