我试图根据我选择的单元格成为用户屏幕上的第一个或最后一个单元格来触发一些代码。我没有尝试捕获数据数组的索引值。只是屏幕上可见的单元格的索引值。我确定这会创建一个可见单元格数组。
NSArray * indexPathsForVisibleRows = [myTableView indexPathsForVisibleRows];
但是我一直在努力尝试捕获基于该数组的索引值。 我试图使用CGPoint并转换它,但我一直收到错误。任何见解都会有所帮助!
答案 0 :(得分:3)
根据该方法的返回值的文档:
每个表示一行的NSIndexPath对象数组 索引和节索引,它们共同标识了一个可见的行 表视图。如果没有可见的行,则返回nil。
从该方法返回的数组包含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
}
}