开发者

How to create view hierarchy programmatically?

开发者 https://www.devze.com 2023-02-18 04:03 出处:网络
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

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号