我有一个横幅数组,并在我的自定义单元格中显示它。当用户点击横幅广告时,我会推送detailViewController
并打开应用内浏览器。
我每隔5秒换一次横幅。为此,我使用NSTimer
来安排选择器调用。一切都很好......直到用户点击横幅并从detailViewController
返回。当用户回来时,NSTimer表现得非常奇怪。它会在5秒后更改第一个横幅(指定),然后在1秒后更改下一个横幅,依此类推。
她是我正在使用的代码:
#pragma mark - User Methods
-(void) resetBannerRotationTimer {
[self.bannerTimer invalidate];
self.bannerTimer = nil;
self.timeInterval = 5.0f;
self.bannerTimer = [NSTimer scheduledTimerWithTimeInterval:self.timeInterval target:self selector:@selector(rotateBanner) userInfo:nil repeats:YES];
self.timeInterval = self.bannerTimer.timeInterval;
[[NSRunLoop currentRunLoop] addTimer:self.bannerTimer forMode:NSRunLoopCommonModes];
}
rotateBanner:
-(void) rotateBanner {
BannerCell *bannerCell = (BannerCell *)[self.dealsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[bannerCell updateBanner];
}
在我的updateBanner
方法中,我正在处理UIPageControl
更改网页。 (我不认为代码需要发布)。
我在resetBannerRotationTimer
方法中调用viewWillAppear
方法。
答案 0 :(得分:-1)
我认为你错过了解雇你的计时器
在计时器安排后添加此行
[self.bannerTimer fire];