Custom UITableViewCell will not redraw to setNeedsDisplay

I created my own UITableViewCellclass with UIButton, a UIImageand two UILabels. The button and image overlap, and only one is displayed at a time. Expected behavior: you touch the button, the button disappears and the image displays. UITableViewCellsset for reuse. Here is my code:

Constructor:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        unheartButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];

        unheartButton.backgroundColor = [UIColor clearColor];
        unheartButton.frame = CGRectMake(10, 13, 20, 18);

        [unheartButton addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside];   
        [unheartButton setBackgroundImage:[UIImage imageNamed:@"redheart.png"] forState:UIControlStateNormal];

        imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(12, 13, 16, 16);

        NSMutableArray *array = [[NSMutableArray alloc] init];

        for (int ndx = 1; ndx < 13; ndx++) {
            [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"icon-loading-%d (dragged).tiff", ndx]]];
        }

        imageView.animationImages = array;
        imageView.animationDuration = 1;

        [array release];

        [self.contentView addSubview:imageView];
        [self.contentView addSubview:unheartButton];

        return self;
    }
}

    - (void) setModel:(MyModel *)myModel {
        model = myModel;

        if (model.hideImage) {
                imageView.hidden = YES;
                unheartButton.hidden = NO;
        else {
                imageView.hidden = NO;
                unheartButton.hidden = YES;
        }
    }

Press the button:

- (IBAction) onButtonClick: (id) sender {
    model.hideImage = NO;

    unheartButton.hidden = YES;
    imageView.hidden = NO;
    [imageView startAnimating];

    [self setNeedsDisplay];
    [self.contentView setNeedsDisplay];
    [self.unheartButton setNeedsDisplay];
    [self.imageView setNeedsDisplay];
}

I call setNeedsDisplayeverything, but nothing happens. If I scroll the screen and make a backup, the button is hidden and the download icon is now displayed, but this only happens after scrolling. I'm not sure what I need to do to rewrite the cell.

+5
1

UITableView ..; .

reloadRowsAtIndexPaths: withRowAnimation: . . : UITableViewCell ?

+2

All Articles