开发者

Getting a specific UITableViewCell out of a UITableView

开发者 https://www.devze.com 2023-01-18 11:53 出处:网络
I was wondering, is there any methods to retrieve a specific cell from an UITableView? For example, from where I am I can access my UITableView, so I would like to call something like cellForRowAtInt

I was wondering, is there any methods to retrieve a specific cell from an UITableView?

For example, from where I am I can access my UITableView, so I would like to call something like cellForRowAtInteger:3 and that would return a cell so I could mani开发者_运维百科pulate it.

Any ideas?

Thanks!


You can use -cellForRowAtIndexPath: method from UITableView. But remember that it will return nil if the cell is not visible.


Make your own function to create an NSIndexPath from your NSInteger.

-(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];
}

You can then call it anywhere using:

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

If you have more than one section, then you need to change the 0 accordingly to the section.

0

精彩评论

暂无评论...
验证码 换一张
取 消