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

标签 ios ios4 ipad

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

相关文章:

ios - 如何在iPad应用程序上显示我的pdf文件

ios - UICollectionView 刷新数据

ios - 域=NSURLError域代码=-1021 "request body stream exhausted"

ios - 如何在 UITests 的 `detailTextLabel` 中访问 `tableViewCell`?

ios - 为非半透明导航栏swift 4设置背景图片

iphone - 在 MFMailComposeViewController 中获取收件人列表

ios 核心数据 - 将实体记录复制到另一个实体

ios - 将多行文本放入动态改变大小的节点

PDF 选择器——就像媒体选择器——可能吗?

iphone - 从自定义类中获取特定类型的属性