ios - pushViewController 不工作

标签 ios uinavigationcontroller appdelegate

我在 appDelegate 中设置了 navigationController,但现在我在另一个 ViewController 中记忆起它,但它不起作用。这是我的代码:

在appDelegate.h中

  #import <UIKit/UIKit.h>

  @class RootViewController;

  @interface AppDelegate : UIResponder <UIApplicationDelegate>

  @property (strong, nonatomic) UIWindow *window;

  @property (strong, nonatomic) RootViewController *viewController;

  @property (strong, nonatomic) UINavigationController * navigationController;

  @end

在 appDelegate.m 中

  @implementation AppDelegate

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

      RootViewController * rootMenu;
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    rootMenu = [[RootViewController alloc] initWithNibName:@"RootViewController_iPhone" bundle:nil];
    } else {
    rootMenu = [[RootViewController alloc] initWithNibName:@"RootViewController_iPad" bundle:nil];
}

     self.viewController = rootMenu;

     self.navigationController =[[UINavigationController alloc]initWithRootViewController:rootMenu];

     self.window.rootViewController = self.viewController;

    [self.window makeKeyAndVisible];
     return YES;
    }

在rootViewController.h中

    #import <UIKit/UIKit.h>

    @interface RootViewController : UIViewController <UIGestureRecognizerDelegate>{

     }

    @property (nonatomic, retain) UIImageView * bigImageView;
    @property (nonatomic, assign)BOOL fromRootViewController;


     - (void)handleTap:(UITapGestureRecognizer *)recognizer;




    @end

在 RootViewController.m 中

   - (void)handleTap:(UITapGestureRecognizer *)recognizer{

          if (recognizer.state == UIGestureRecognizerStateEnded)     {
          MenuViewController * menu = [[MenuViewController alloc]initWithNibName:@"MenuViewController" bundle:nil];

          self.fromRootViewController = YES;

          [self.navigationController pushViewController:menu animated:YES];



     }
   }

提前致谢

最佳答案

将 AppDelegate 中的第 1 行替换为第 2 行

1)self.window.rootViewController = self.viewController;

2)self.window.rootViewController = self.navigationController;

它会起作用

reason is that there is no navigationController in your application

关于ios - pushViewController 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12746120/

相关文章:

ios - 在方法运行之前使用可达性检查连接

php - 如何安全地将密码从 iOS 应用程序发布到 PHP 服务器?

ios - 在 iOS 应用程序中实现 sqlite3_busy_timeout()

ios - 核心数据 NSManagedObject 没有有效的 NSEntityDescription

ios - 从 UIActivityViewController 关闭邮件后 UINavigationBar 消失

ios - Navigation Bar 消失 Change Root ViewController 然后重新赋值

iOS:应用程序启动后, UIApplication.sharedApplication.keyWindow.rootViewController==nil

ios - 如何检查我的 applicationIconBadgeNumber 值?

ios - GPUImage Lookup Filter - 创建大于 512² 颜色的颜色深度

ios - 以编程方式呈现 ViewController 时导航栏未加载