2010-02-17 48 views
1

我在UITableViewCell中有一个UIImageView。 UIImageView动画。出于某种奇怪的原因,当细胞离开视野时,动画停止。 UIImageView永远不会再被初始化,并且UIImageView永远不会被明确地告知 - (void)stopAnimating;所以我不确定它为什么停止。UIImageView动画在UITableView中停止

以下是我的cellforRowAtIndexPath的有趣部分:。正如你可以

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]; 

正如你所知道的,我没有设置相应的动画开始点小区,因为没有一个内置在一个UIImageView方式。

+0

通过“视图外”,你的意思是当UITableViewCell滚动屏幕? – 2010-02-17 14:53:49

+0

你可以发布你的tableView:cellForRowAtIndexPath:方法吗? – 2010-02-17 14:56:38

+0

当我说“离开视图”时,我指的是UITableViewCell何时位于UITableView的可见区域之外。 – 2010-02-17 15:04:22

回答

0

我写了一个解决方法。我只是使用NSTimer来手动调整UIImageView的动画。它效果很好。

0

当单元格离开屏幕时,它将被释放,并且子视图(图像视图)也将被释放,导致动画被停止。

保留-retain - 为了避免这种情况,在某处放置该图像视图的实例。

+1

这不是问题。包含UIImageView的视图不会被取消分配。除了动画UIImageView之外,其他每个子视图都保留它的状态。 – 2010-02-17 15:07:34

2

你应该已经在你的单元格上展示了UIImageView,并在cellForRowAtIndexPath方法中启动了动画,或者重写了UITableViewCell的prepareForReuse方法,并在该方法中启动了动画。

prepareForReuse在每次您的可重用单元从可重用的队列中出队时调用。需要注意的是,如果你要使用它,不要忘记调用超类的实现。