Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 运行nstimer以显示广告,但仅显示在特定的视图控制器上_Ios_Objective C_Nstimer - Fatal编程技术网

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继承。