2013-06-07 8 views
1

iOS-Project에서 탐색 컨트롤러를 사용하려고합니다.UINavigationController 및 자동 레이아웃 : RootViewController의보기가 표시되지 않습니다.

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

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

    // Generate RootViewController (some auto-layout stuff is going on here) 
    MyLayoutDescriptionGeneratorClass *generator = [MyLayoutDescriptionGeneratorClass new]; 
    MyViewControllerClass *vc = [generator generateViewController]; 

    self.navController = [[UINavigationController alloc] initWithRootViewController:vc]; 
    [self.window setRootViewController:self.navController]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
내보기 컨트롤러의

viewDidLoad은 다음과 같습니다 : 여기 내 AppDelegate에 클래스의 설정은 내가 & 실행을 빌드 할 때 탐색 모음이 표시되고 제목이 Hello로 설정

-(void)viewDidLoad{ 

    [super viewDidLoad]; 
    // Generate all subviews and their constraints   
    self.view = [MyObjectManagerClass viewForParentViewDescription:_parentViewDescription]; 
    self.title = @"Hello"; 
} 

- 불행히도보기 컨트롤러보기가 표시되지 않습니다. 나는이

[self.window setRootViewController:self.navController]; 

모두 같은 탐색 컨트롤러를 가지고가는 경우에

잘 작동합니다. 누구든지 제발 도와 주실 래요?

+0

당신은 의미합니까;'잘 작동? 내비게이션 컨트롤러가없는 –

+0

. 하지만보기가 올바르게 표시됩니다. – Chrizzor

+0

자동 레이아웃으로 무언가를해야한다고 생각하십니까? – Chrizzor

답변

1

난 그냥 수정했다 나의 viewDidLoad :

당신이`[self.window의 setRootViewController : VC]을 사용하는 경우
-(void)viewDidLoad{ 
    [super viewDidLoad]; 
    // Generate all subviews and their constraints   
    UIView *view = [RuiObjectManager viewForParentViewDescription:_parentViewDescription]; 
    self.title = @"Hello"; 

    // Add generated view to self.view and create constraints 
    [self.view addSubview:view]; 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(@"view", view)]]; 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(@"view", view)]]; 
} 
+1

그냥 FYI : NSDictionaryOfVariableBindings()의 목적은 키의 변수 이름을 반복 할 필요가 없다는 것입니다. 따라서 NSDictionaryOfVariableBindings (view)는 사전을 작성합니다. @ @ @ "view": view }' –

관련 문제