我有一个按字母顺序划分的表格视图。我在每个部分的页脚的 UIImage 视图中显示动画横幅,并且需要确定单击 UIImage 视图时显示的图像。我在调用 startAnimating 之前设置了一个计时器。计时器每 5 秒触发一次,与动画变化的速率相同,但计时器的触发速度要快得多。有时它会在 5 秒内发射 2 或 3 次。这是我启动计时器和动画的代码:
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section {
...
imgAdBar = [[bannerView alloc]initWithFrame:CGRectMake(footer.frame.origin.x,footer.frame.origin.y,footer.frame.size.width,footer.frame.size.height)];
imgAdBar.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@", [animationArray objectAtIndex:0]]];
[imgAdBar saveBannerArray:animationArray];
[imgAdBar setUserInteractionEnabled:YES];
imgAdBar.animationImages = images;
imgAdBar.animationDuration=[images count]*5;
imgAdBar.animationRepeatCount=0;
timerCount=0;
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerRunning:) userInfo:nil repeats:YES];
[imgAdBar startAnimating];
[footer addSubview:imgAdBar];
footer.backgroundColor = [UIColor clearColor];
}
return footer;
}
这是选择器:
-(void)timerRunning:(NSTimer*)theTimer
{
NSLog(@"timerCount=%d",timerCount);
imgAdBar.timerCount=timerCount;
if (timerCount==numAnimationImages) {
timerCount=0;
}
NSLog(@"currentImage=%@",[animationArray objectAtIndex:timerCount]);
timerCount++;
}
我计划使用该计时器来索引我的图像数组,以便我可以知道显示的是哪个。任何人都知道为什么它应该在它应该触发的时候不触发?感谢您的帮助!