설명
self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
self.navigationController = [[ UINavigationController alloc ] initWithRootViewController:self.viewController ];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
그런 다음 당신은 당신이 할 수있는 새로운 VC를 제시 할 때. 모든 iOS 응용 프로그램에는 적어도 하나의 UIWindow
이 있습니다. 항상 UIViewController
개체가 루트로 설정되어 있어야합니다. 이는 화면의 사용자가 볼 수있는 응용 프로그램의 초기 ViewController로 설정한다는 것을 의미합니다. UINavigationController
은 ViewControllers를 내부에 밀어 넣는 스택 컨테이너이며이 실속 상태의 맨 위 ViewController는 기본적으로 화면에서만 볼 수 있습니다. 하지만 초기에 UIViewController
은 UIWindow
과 UINavigationController's
루트보기 컨트롤러로 모두 루트보기 컨트롤러로 설정해야합니다. 시작점이 필요합니다. UIWindow
루트보기 컨트롤러는 언제든지 변경 될 수 있지만 UINavigationController
과 같이 작동하면 루트보기 컨트롤러를 변경할 수 없습니다.
이제 코드에서 어떻게되는지 설명해 드리겠습니다.
self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
//In Above Line you are loading a UIViewController from a Xib file name RootViewController.xib into viewController property
self.navigationController = [[ UINavigationController alloc ] initWithRootViewController:self.viewController ];
//In Above Line You are allocating a new navigation controller programatically with a root/initial view controller and you are passing your previously loaded view controller to be set as root view controller of this navigation.
self.window.rootViewController = self.navigationController;
//In Above Line You are assigning your navigationController to UIWindow object this means you want your view controllers to be managed in a stack so that if you push a view controller you can snap back easily with a single line of code.
[ self.navigationController popViewControllerAnimated:YES ];
//In This Line you are removing your Top view Controller from a navigation stack Like the Back button does in Setting>General to Setting in iPhone/iPad
특별히 이해하지 못하는 점은 무엇입니까? 스토리 보드가 아닌 XIB 파일을 사용하는 상당히 오래된 학교 코드입니다. 그러나 그것은 나에게 자급 자족스러운 것처럼 보입니다. –
첫 번째 네 줄은 무엇을합니까? 마지막 세 가지는 navigationController를 만들고 viewControllers 사이를 탐색하는 것입니다. – 12345
첫 번째 네 개는 해당 요소와 할당에 대한 생성자/초기화 코드입니다. – mike510a