我通常在 IB 中创建我的 View 层次结构,但这次我需要在我的代码中进行。基本上我已经有了我的自定义 View ,但我希望它包含在 UINavigationController 中。那么我该怎么做呢?
最佳答案
如果您希望将其嵌套在导航 Controller 中,您应该使用:
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];
祝你好运
编辑
添加此代码(在发布之前):
navigationController.navigationItem.leftBarButtonItem=nil;//change it to rightBarButtonItem if the button is on the right.
关于ios - 如何以编程方式创建 View 层次结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5369453/