gpt4 book ai didi

ios - 如何以编程方式创建 View 层次结构?

转载 作者:行者123 更新时间:2023-12-01 19:28:06 24 4
gpt4 key购买 nike

我通常在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com