【问题标题】:Getting row number in scrollViewDidEndDecelerating在scrollViewDidEndDecelerating中获取行号
【发布时间】:2011-04-22 17:29:54
【问题描述】:

当我使用时

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
     NSArray *visibleCells = [my_table visibleCells];

我想知道可见的行数(在 my_table 中)(使用 visibleCells)。

例如,如果我这样做了

[visibleCells count];

我知道有 5 行可见,但我需要知道实数(例如:表格视图中的数字 3、4、5、6、7)。

有可能吗?

【问题讨论】:

    标签: iphone uitableview uiscrollviewdelegate nsindexpath


    【解决方案1】:

    您可以在带有数组的第一个和最后一个对象的表视图上调用 indexPathForCell: 以获取两个索引路径。

    【讨论】:

    • 谢谢你,但是......我如何调用 indexPathForCell: 一个特定的单元格?以及如何获取 NSIndexPath?
    【解决方案2】:

    解决了!

    使用这个

    UITableViewCell *currentCell = [visibleCells objectAtIndex:i];
    NSIndexPath *indexPath = [tabella_gallery indexPathForCell:currentCell];
    

    工作正常!

    【讨论】:

      【解决方案3】:

      这是我使用的一种方法

      func loadImagesForVisibleRows() {
      
          // Get the visible cells indexPaths
          let indexes: Array = tableView.indexPathsForVisibleRows()!
      
          // Loop through them to determine whether visible or not
          for index in indexes {
      
              let row = index.row
              // Do what you need to do
      
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2012-06-14
        • 2017-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-16
        • 2013-01-10
        • 2021-01-24
        相关资源
        最近更新 更多