从AppDelegate和Tab Bar推送View Controller

use*_*452 3 uitabbarcontroller uinavigationcontroller pushviewcontroller ios appdelegate

我的应用程序设置为标签栏控制器作为RootViewController,并且每个标签都有一个NavigationController.当执行某些操作时,我希望应用程序将其推入ViewController屏幕.这个流程是当应用程序启动或从后台打开时,它会检查存储的NSDate并将其与当前日期进行比较.如果满足正确的条件,则显示a UIAlertView.如果选择了名为"Push"的按钮,它将运行代码以推送新视图.这就是我需要从中运行的原因AppDelegate,因为如果在后台使用该应用程序,则无法保证可以打开哪个选项卡.由于每个选项卡包含一个NavigationController,我想我可以从AppDelegate运行它:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

      if (alertView.tag == 100) {
         if (buttonIndex == 0) {
              //Cancel
              NSLog(@"Cancel");
          }
         if (buttonIndex == 1) {
              NSLog(@"OK");
              [self.tabBarController.selectedViewController pushViewController:self.newView animated:YES];
         }
     }
}
Run Code Online (Sandbox Code Playgroud)

我收到一条警告信息UIViewController may not respond to -pushViewController:animated.关于我还能做什么的任何建议?

rde*_*mar 10

selectedViewController的返回类型是UIViewController,因此您需要告诉编译器它实际上是一个导航控制器.你用演员表演,

[(UINavigationController *)self.tabBarController.selectedViewController pushViewController:self.newView animated:YES];
Run Code Online (Sandbox Code Playgroud)