Ios 运行nstimer以显示广告,但仅显示在特定的视图控制器上
这很好,但我需要它出现在某个类名“食物”中,而不是其他类。任何提示都将不胜感激Ios 运行nstimer以显示广告,但仅显示在特定的视图控制器上,ios,objective-c,nstimer,Ios,Objective C,Nstimer,这很好,但我需要它出现在某个类名“食物”中,而不是其他类。任何提示都将不胜感激 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // [Shared instance]; [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// [Shared instance];
[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(ad) userInfo:nil repeats:YES];
}
-(void)ad{
[ALInterstitialAd showOver:self.window];
}
好吧,如果你需要在某一节课上展示它,老师会在那节课上做。您可以使用
viewDidLoad
、viewDidAppear
和viewWillAppear
来实例化NSTimer
为什么不将代码放在该视图控制器中?在ViewDidDisplay中启动计时器,并在ViewDidEnglishe中使其无效。是否可以子类UIViewController并添加@rdelmar提到的代码?然后,您可以在需要显示广告的视图控制器中继承此类,并在不应显示广告的视图控制器中直接从UIViewController继承。