2012-05-15 2 views
5

스토리 보드에서 기본보기 컨트롤러를 대체하여 대신 다른 컨트롤러를 표시 할 수 있습니까? 물론 이것은 AppDelegate에서 모두 발생합니다.실행시 스토리 보드 기본보기 컨트롤러를 변경하십시오.

+1

기본 ViewController는 최신 SDK의 info.pList에 선언되어 있습니다. 시작시에 무엇인가를 확인한 다음, 어떤 viewcontroller를 푸시할지 결정해야합니까? – Martol1ni

+0

@ Martol1ni 네, 당신이 말한 것은 정확하게 제가 찾고있는 것입니다. – Jacksonkr

+0

UINavigationController를 사용하고 있습니까? – Martol1ni

답변

10

@ Martol1ni 답변을 사용하고 싶었지만 불필요한 스토리 보드 혼란에서 벗어나고 싶었 기 때문에 코드를 약간 수정했습니다. 그러나 나는 당신에게 영감을주는 대답에 +1을 주었다.

다음 컨트롤러를 모두 기본 컨트롤러에 추가했습니다.

- (void)gotoScreen:(NSString *)theScreen 
{ 
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:theScreen]; 
    [app.window setRootViewController:screen]; 
} 

그런 다음 로직이 발생하는 곳에서 필요에 따라 다음을 호출합니다.

5

나는 UINavigationController에 꼭 rootView를 포함시킬 것이므로 두 가지가 아니라 세 가지 뷰가 있습니다. 그 하나는 결코 시작되지 않으며, 다른 모든 것들을 통제합니다. 그런 다음이 메소드를 다음과 같이 구현하십시오.

- (void) decideViewController { 
    NSString * result; 
    if (myBool) { 
     result = @"yourIdentifier"; 
    } 
    else { 
     result = @"yourOtherIdentifier"; 
    } 
    self.navigationController.navigationBarHidden = YES; // Assuming you don't want a navigationbar 
    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:@"view1ident"]; 
    [self.navigationController pushViewController:screen animated:NO]; // so it looks like it's the first view to get loaded 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self decideViewController]; 
} 

첫 번째보기가로드 된 것처럼 보입니다. NIBS를 사용하고 있다면, AppDelegate에서 모든 것을 할 수 있습니다.