I usually create my view hierarchy's in IB b开发者_Go百科ut this time I need to do it in my code. Basically I already have my custom view but I want it to be contained inside a UINavigationController. So how can I do that?
If you wish to nest it in a Navigation controller you should use :
UIViewController * myViewController = [[GameController alloc] init];
myViewController.view = yourCustumeView;//if you are trying to add a UIView
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:myViewController];
[self.navigationController pushViewController:navigationController animated:YES];
[navigationController release];
[myViewController release];
Good luck
EDIT add this code (before the release):
navigationController.navigationItem.leftBarButtonItem=nil;//change it to rightBarButtonItem if the button is on the right.
If you want to create several ViewControllers then you can allocate them in code and then in order to show them just push it like this:
RegistrationViewController * regView= [[RegistrationViewController alloc] init];
[self.navigationController pushViewController:regView animated:YES];
精彩评论