views:

188

answers:

3

I have a UIImageView inside of a UITableViewCell. The UIImageView animates. For some odd reason, when the cell goes out of view, the animation stops. The UIImageView is never initialized again and the UIImageView is never explicitly told to - (void)stopAnimating; so I'm not sure why it's stopping.

Here's the interesting parts of my cellforRowAtIndexPath:. As you can

cell = (BOAudioCell *)[tableView dequeueReusableCellWithIdentifier:AudioCellIdentifier];
if (!cell) {
    cell = [[[BOAudioCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AudioCellIdentifier] autorelease];
    BOPlayControl *playControl = [(BOAudioCell *)cell playControl];
    [[playControl playbackButton] addTarget:self action:@selector(playbackButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
}

int index = [indexPath row];

BOModel *model = [models objectAtIndex:index];
[[(BOAudioCell *)cell titleLabel] setText:[model title]];
[[(BOAudioCell *)cell favoriteButton] addTarget:self   action:@selector(favoriteButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

As you can tell, I'm not setting the appropriate animation begin point for the cell because there is not a built in way with a UIImageView.

A: 

When the cell goes off-screen, it will be released, and the subview (the image view) will be released as well, causing the animation to be stopped.

Keep a -retain-ed instance of that image view somewhere to avoid this.

KennyTM
That's not the problem. The view encompassing the UIImageView doesn't get deallocated. Every other subview retains it's state besides the animating UIImageView.
Dylan Copeland
A: 

I wrote a workaround. I'm just using a NSTimer to coordinate manually animating the UIImageView. It works great.

Dylan Copeland
A: 

You should have exposed the UIImageView on your cell and started the animation in the cellForRowAtIndexPath method or do an override of the prepareForReuse method of the UITableViewCell and started the animation in that method.

prepareForReuse is called every time your reusable cell is dequeued from the reusable queue. Just to note, if you were to use this, do not forget to invoke the superclass implementation.

bstahlhood