简体   繁体   中英

Starting navigation controller from appDelegate

Can anyone tell me how to start UINavigationContoller from ÀppDelegate ? I can start a ? I can start a rootViewContoller but cannot start a specific UIViewController like I was trying in commented code. The commented code starts the **ChooseTableViewController** but does not display like I was trying in commented code. The commented code starts the **ChooseTableViewController** but does not display UINavigationBar`. whats the better approach? Here is my code

- (void)setRootViewController:(NSString *)storyBoardName {
    //set the Root ViewController

    UIStoryboard *story = [UIStoryboard storyboardWithName:storyBoardName 
                                                    bundle:nil];
    UINavigationController *newViewController = 
                                 [story instantiateInitialViewController];
    self.window.rootViewController = newViewController;



    /*
    ChooseTableViewController *chooseTableViewController = 
      [story instantiateViewControllerWithIdentifier:@"ChooseTableViewController"];

    self.window.rootViewController = chooseTableViewController;

    */

}

Appdelegate.h

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;

Appdelegate.m

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

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

            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

       self.navigationController  = [storyboard instantiateViewControllerWithIdentifier:@"navigation"];
              UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ChooseTableViewController"];
              navigationController=[[UINavigationController alloc]initWithRootViewController:viewController];
     self.window.rootViewController =self.navigationController;
            [self.window makeKeyAndVisible];
        return YES;
    }
// Your main storyboard
UIStoryboard *story = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];

// Your root navigation controller
UINavigationController *newViewController = [story instantiateInitialViewController];

// Your root view controller for root navigation controller
ChooseTableViewController *chooseTableViewController = [story instantiateViewControllerWithIdentifier:@"ChooseTableViewController"];

// Set your view controller as root view controller of your root navigation controller
newViewController.rootViewController = chooseTableViewController;

// set your root navigation controller
self.window.rootViewController = newViewController;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM