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

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

问题描述

我在一个应用程序中工作,我有 UITableView 中的数据。它就像一个向下钻取的应用程序。用户将单击一行,将转到下一页,显示 UITableView 中的更多记录。但在我的情况下的问题是,我不知道用户可以钻多少级别。级别数量不固定。所以现在我想以编程方式创建和添加viewcontrollers。可能吗??如果有,怎么样?
提前感谢。

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;

您是否拥有自己编码的视图控制器?在这种情况下,您可能不需要设置视图属性,因为它已在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天全站免登陆