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];
[[(BOAudioCe开发者_高级运维ll *)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.
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.
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.
I wrote a workaround. I'm just using a NSTimer to coordinate manually animating the UIImageView. It works great.
精彩评论