views:

270

answers:

1

I'm trying to change the custom accessoryView of a uitableviewcell immediately after the user clicks on the cell. How would I do this?

For the record, I'm using Matt Gallagher' custom table view tutorial:

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

Download link for source: http://projectswithlove.com/projects/EasyCustomTable.zip


EDIT

Tried this code, but it just changes the accessory AFTER touch-up. Also tried willSelectRowAtIndexPath with same result.

- (NSIndexPath *)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIImage *indicatorImage = [UIImage imageNamed:@"indicatorSelected.png"];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
    return indexPath;
 }

EDIT

Problem solved by making the background image of the cell contain the accessories. so the accessory was 'faked' by making it part of the image

A: 

You could change the accessoryView in the selection method as shown:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryView = newView;
}

This just grabs the current cell that was selected and then changes the accessory view of it. Your view object would go where newView is.

rickharrison
No quite working for me. See updated question
cannyboy