views:

27

answers:

2

Hi!

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 manipulate it.

Any ideas?

Thanks!

+2  A: 

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

Vladimir
This methods needs a NSIndexPath, and I'd like to be able to pass a NSInteger... But thanks :) (- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath)
Tom
you can easily create NSIndexPath using +indexPathWithRow:inSection: method. or you can write convenience function that accepts integer as parameter and creates nsindexpath internally. but as related UITableView methods work with index paths you will need to use them too anyway...
Vladimir
A: 

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.

elcool