ios - 捕获单元格的索引值,但仅来自屏幕上的可见单元格

标签 ios objective-c uitableview nsarray nsindexpath

我正在尝试根据我选择的单元格是用户屏幕上的第一个还是最后一个单元格来触发一些代码。我不是要捕获数据数组的索引值。只是屏幕上可见的单元格的索引值。我确信这会创建一个可见单元格数组。

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/

相关文章:

ios - XCode 4.5 中的代码签名身份

ios - Kofax Capture Mobile SDK 是否有适用于 iOS 的试用版?

ios - TableView背景渐变毛刺

ios - 带有圆形边框的 UIImage,就像在联系人中一样

ios - UITableViewController 中的节标题和 TableView 单元格出现问题

ios - 类型 'URL' 的值没有成员 'URLByAppendingPathComponent'

ios - 如何使用 iOS Masonry(自动布局)将两个按钮放置在彼此旁边

ios - 如何在 IOS/SWIFT/OBJ-C/CORDOVa 上获取 Finger iD(哪个手指用于触摸 ID)或唯一触摸 ID

ios - 具有不确定数量的 UIImageViews 的 UITableViewCell

ios - viewForHeaderInSection 对齐错误(Swift 3)