代码之家  ›  专栏  ›  技术社区  ›  Tommy B.

从UITableView中获取特定的UITableViewCell

  •  0
  • Tommy B.  · 技术社区  · 15 年前

    我想知道,有没有什么方法可以从UITableView中检索特定的单元格?

    例如,从我所在的位置,我可以访问我的UITableView,所以我想调用CellForRowatineger:3这样的函数,它将返回一个单元格,以便我可以对其进行操作。

    有什么想法吗?

    谢谢

    2 回复  |  直到 15 年前
        1
  •  2
  •   Vladimir    15 年前

    你可以用 -cellForRowAtIndexPath: 方法从UITableView中删除。但请记住,如果单元格不可见,它将返回零。

        2
  •  1
  •   elcool codeVerine    15 年前

    使用自己的函数从NSInteger创建NSIndexPath。

    -(UITableViewCell *) getCellAt:(NSInteger)index{
      NSUInteger indexArr[] = {0,index};  // First one is the section, second the row
    
      NSIndexPath *myPath = [NSIndexPath indexPathWithIndexes:indexArr length:2];
    
      return [self tableView:[self tableView] cellForRowAtIndexPath:myPath];
    }
    

    然后,您可以使用以下命令在任何地方调用它:

    UITableViewCell *hello = [self getCellAt:4];  // replace 4 with row number
    

    如果有多个部分,则需要更改 0 根据本节。

    推荐文章