如何以编程方式创建 UIViewController? [英] How do I create a UIViewController programmatically?

查看:24
本文介绍了如何以编程方式创建 UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用中工作,我在 UITableView 中有数据.它就像一个向下钻取的应用程序.用户将单击一行并转到下一页,在 UITableView 中显示更多记录.但就我而言,问题是我不知道用户可以钻多少级.级别数不固定.所以现在我想以编程方式创建和添加视图控制器.是否可以??如果是,如何?提前致谢.

I am working in a app where i have data in UITableView. It is like a drill down application. User will click on a row and will go to next page showing more records in a UITableView. But problem in my case is that i dont know upto how many level user can drill. The number of levels are not fixed. So now i am thinking to create and add the viewcontrollers programmatically. Is it possible?? if yes how? thanks in advance.

推荐答案

UIViewController *controller = [[UIViewController alloc] init];
controller.view = whateverViewYouHave;

你有自己编写的视图控制器吗?在这种情况下,您可能不需要设置 view 属性,因为它已在 IB 中设置,如果这是您使用的.拥有控制器后,您可以将其推送到 navigationController 或以模态方式查看等.

Do you have your own view controller that you coded? In that case you probably don't need to set the view property as it has been set in IB if that is what you used. When you have your controller you can push it onto the navigationController or view it modally etc.

这篇关于如何以编程方式创建 UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆