簡體   English   中英

pushViewController不起作用

[英]pushViewController don't work

我在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;

它會工作

原因是您的應用程序中沒有navigationController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM