2017-04-17 97 views
0

誰能告訴我如何從ÀppDelegate? I can start a開始UINavigationContoller rootViewContoller but cannot start a specific UIViewController like I was trying in commented code. The commented code starts the **ChooseTableViewController** but does not display UINavigationBar`。 什麼是更好的方法? 這裏是我的代碼從appDelegate啓動導航控制器

- (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; 

    */ 

} 
+0

把'ChooseTableViewController'作爲'UINavigationController'的RootViewController的會爲你工作。 –

回答

0
// 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; 
1

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; 
    } 
+0

什麼是instantiateViewControllerWithIdentifier:@「導航」在這裏??它在該行崩潰 – Shelby

+0

這意味着導航控制器將是您的初始視圖控制器和導航控制器的標識是@「導航」 –

+0

但它在那裏崩潰 – Shelby

相關問題