在viewDidAppear
中,我会在3秒后向用户显示弹出窗口。如果用户在计时器开始后导航到另一个viewController
,该怎么办?所选功能将尝试执行&当superview不再在屏幕上时显示弹出窗口。应用程序不会崩溃或抛出任何错误,但我想确认这是安全的。我应该在选择器方法中设置BOOL
并断言isCurrentView
是YES
吗?
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:@selector(showPopup) withObject:nil afterDelay:2.5];
}
答案 0 :(得分:1)
viewDidDisappear
中的
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:(BOOL)animated];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showPopup) object:nil];
}