Programming iOS: clarifications about Root View Controller

后端 未结 4 691
生来不讨喜
生来不讨喜 2020-12-15 11:20

Through this question I would like to know if I understand well the notion of Root View Controller.

In iOS application, the Root View Controller (RVC) is the control

4条回答
  •  甜味超标
    2020-12-15 11:34

    Now, an UIWindow has also a rootViewController property. When running the previous snippet of code, does that property gets populated with the rvcController or do I have to set it explicity?

    You have to set it explicitly, and if you do, you can remove the addSubview line, because that's handled automatically when you set a root view controller.

    Then, in a UINavigationController it is possible to set a RVC that is different from the previous RVC set for the entry point.

    Of course, a navigation controller's root view controller has nothing to do with that of the window.

    In this case, the first time I add a controller to the navigationController stack (pushing a new controller on it), does the framework set that controller as the RVC for the navigationController or do I have to set it explicity through initWithRootViewController method?

    initWithRootViewController is just a shortcut for initializing an empty navigation controller and pushing the first (root) view controller onto the stack. Note that rootViewController is not a property of UINavigationController, you would access it via [navController.viewControllers objectAtIndex:0].

提交回复
热议问题