Ortensia C.
Ortensia C.

Reputation: 4716

pushViewController don't work

I set navigationController in the appDelegate, but now I recall it in another ViewController and it does not work. This is my code:

In the 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

In the 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;
    }

In 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

In the 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];



     }
   }

Thanks in advance

Upvotes: 0

Views: 1031

Answers (1)

Narayana Rao Routhu
Narayana Rao Routhu

Reputation: 6323

Replace below line 1 with 2 in AppDelegate

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

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

it will work

reason is that there is no navigationController in your application

Upvotes: 3

Related Questions