Objective-C / Cocoa: loading UIViews correctly
Suppose that I have created UIView
, MyView
in Interface Builder, and I plugged it (set it to File Owner) in the class UIViewController
, MyViewController
.
Now I would like to present a performance. It's just a different look, so I don't want to present it as a modal view.
How should I display it? Should I add it as a spy on my window? If so, where does it go relative to my other views? Should I somehow present it as a standalone view and disable other views? What is the mechanism?
a source to share
It depends on how you want the application to function.
You can either add MyView as a subzone of the current view using the UIView addSubview if you have a Done button or something like that in 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 return to the main view (like mail, notes, etc.), the most common way to do this is to add a nav controller to your window and use pushViewController: animated: to present your views ...
MyViewController *myViewController = [[MyViewController alloc]init];
[self.navigationController pushViewController:myViewController animated:YES];
In most situations, I prefer the navigationController approach.
a source to share