我在想,是否有任何方法可以从UITableView中检索特定的单元格?
例如,从我所在的位置,我可以访问我的UITableView,所以我想调用类似cellForRowAtInteger:3的东西,然后返回一个单元格以便我可以操作它。
有什么想法吗?
谢谢!
答案 0 :(得分:2)
您可以使用UITableView中的-cellForRowAtIndexPath:
方法。但请记住,如果单元格不可见,它将返回nil。
答案 1 :(得分:1)
创建自己的函数以从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
更改为该部分。