Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a custom accessoryView in a uitableviewcell?

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

like image 479
cannyboy Avatar asked Apr 13 '26 13:04

cannyboy


1 Answers

Perhaps you can try to reload the cell in willSelectRowAtIndexPath/didSelectRowAtIndexPath:

- (void)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];
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:NO];
 }

Another recommendation: didSelectRowAtIndexPath returns void not NSIndexPath.

like image 103
phse Avatar answered Apr 16 '26 04:04

phse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!