Dylan Copeland
Dylan Copeland

Reputation: 1249

UIImageView Animation Stopping in UITableView

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.

Upvotes: 2

Views: 2033

Answers (3)

bstahlhood
bstahlhood

Reputation: 2006

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.

Upvotes: 3

Dylan Copeland
Dylan Copeland

Reputation: 1249

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

Upvotes: 0

kennytm
kennytm

Reputation: 523164

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.

Upvotes: 0

Related Questions