Stanley
Stanley

Reputation: 4486

Setting the Root View Controller of a UIWindow

I have started a xCode 3 project using the "Create a Window-Based Application" option. 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. (The project has been moved to 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 ?

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.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[root_view_controller presentModalViewController : about_screen animated : YES];

Upvotes: 1

Views: 1328

Answers (1)

greg
greg

Reputation: 4953

rootViewController is a property of UIWindow. That template should have provided you with a MainWindow.xib file which you can open in Interface Builder (since we're talking 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.

If you want to do it programmatically, that template should have also setup a window property in your AppDelegate. You can use that property to assign rootViewController to a UIViewController you instantiate.

Upvotes: 1

Related Questions