2017-04-17 4 views
0

UINavigationContoller을 시작하는 방법을 알려주시겠습니까? ? 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 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

입니다 . –

답변

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; 

당신을 위해 작동합니다`UINavigationController`의 rootViewController로`ChooseTableViewController` 퍼팅 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인가 : @ "navigation"here ?? 그 라인에 충돌이 있습니다 – Shelby

+0

네비게이션 컨트롤러가 초기보기 컨트롤러가되고 네비게이션 컨트롤러의 식별자가 @ "내비게이션" –

+0

이지만 그곳에서 충돌하고 있음을 의미합니다. – Shelby