views:

191

answers:

2

Suppose I have created a UIView, MyView, in Interface Builder, and I have hooked it up (set its File's Owner) to my UIViewController class, MyViewController.

Now, I would like to present view. It's just another view, so I don't want to present it as a modal view.

How do I go about displaying it? Should I add it as a subview of my window? If so, where does it go relative to my other views? Should I present it as a view in its own right somehow, and disable the other views? What is the mechanism?

+1  A: 

It depends on how you want the app to act.

You can either add MyView as a subview of the current view using UIView addSubview if you are going to have a "Done" button or something like that on MyView to remove itself.

// show new view
MyViewController *myViewController = [[MyViewController alloc]init];
[self.view addSubview: myViewController.view];

Or if you want the user to be able to navigate back to the main view(like in mail,notes etc) the most common way to do that would be to add a navigationController to your window and using pushViewController:animated: to present your views.

MyViewController *myViewController = [[MyViewController alloc]init];
[self.navigationController pushViewController:myViewController animated:YES];

I much prefer the navigationController approach in most situations.

Jab