views:

494

answers:

2

I was calling
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

from
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

in order to change the cell accessory. This works fine, but I ended up needing to subclass UITableViewCell. What's the correct way to get the subclassed UITableViewCell? Alternative A: UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

returns an object that is
CustomCell: 0x4527ed0; baseClass = UITableViewCell

but won't respond to
cell.customAccessoryImage;

Alternative B won't compile
CustomCell *cell = [tableView cellForRowAtIndexPath:indexPath];

Thanks in advance!

+1  A: 

You should be able to cast it like this and access it as a CustomCell object

CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
Justin Gallagher
perfect, thanks a lot
Monte Bel
A: 

Justin's right. Are you needing to change the accessory view after the table's set up, though? Typically the best place to do that kind of setup is in -tableView:cellForRowAtIndexPath:.

Noah Witherspoon