简体   繁体   English

设置UIWindow的根视图控制器

[英]Setting the Root View Controller of a UIWindow

I have started a xCode 3 project using the "Create a Window-Based Application" option. 我已经使用“创建基于窗口的应用程序”选项启动了xCode 3项目。 Everything seems to be ok and quite a lot has been done. 一切似乎都还可以,并且已经做了很多工作。 But then it comes to a stage where I wish to add a flip transition to another view. 但是到了我希望向另一个视图添加翻转过渡的阶段。 And the related documentations seem to suggest that I need a rootViewController for my UIWindow to do flip views. 并且相关文档似乎建议我为UIWindow需要rootViewController来进行翻转视图。 (The project has been moved to xCode 4.2) (该项目已移至xCode 4.2)

My questions is : 我的问题是:

Is there a safe and efficient way to add a rootViewController after the project has been started for some time ? 在项目启动一段时间后,是否有一种安全有效的方法来添加rootViewController?

Also have tried the following code : 还尝试了以下代码:

- (void) setup_root_view_controller

{

root_view_controller = [[UIViewController alloc] 
                       initWithNibName : nil 
                       bundle          : nil ];

[root_view_controller setView : [[window subviews] objectAtIndex : 0]]; 

[window setRootViewController : root_view_controller];     

}

The above code compiles and runs ok except that the following "about_screen" doesn't show. 上面的代码可以编译并正常运行,但以下“ about_screen”未显示。

about_screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[root_view_controller presentModalViewController : about_screen animated : YES];

rootViewController is a property of UIWindow . rootViewControllerUIWindow的属性。 That template should have provided you with a MainWindow.xib file which you can open in Interface Builder (since we're talking Xcode 3). 该模板应该已经为您提供了MainWindow.xib文件,您可以在Interface Builder中打开它(因为我们正在谈论Xcode 3)。 You can use right-click and drag from the rootViewController outlet of the UIWindow to the appropriate UIViewController you've added to the XIB in Interface Builder. 您可以单击鼠标右键,然后从UIWindowrootViewController出口拖动到已在Interface Builder中添加到XIB的相应UIViewController

If you want to do it programmatically, that template should have also setup a window property in your AppDelegate . 如果要以编程方式执行此操作,则该模板还应该在AppDelegate设置一个window属性。 You can use that property to assign rootViewController to a UIViewController you instantiate. 您可以使用该属性将rootViewController分配给您实例化的UIViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM