简体   繁体   English

将UITableViewController插入其他UIView

[英]Insert UITableViewController into Other UIView

I've got a UITableViewController that inserts custom UITableViewCells into a UITableView. 我有一个UITableViewController,它将自定义UITableViewCells插入到UITableView中。 Is there a way that I can put this UITableController/View combo into different views? 有没有办法可以将这个UITableController / View组合放到不同的视图中? I've got the behavior of the UITableView acting the way I want, I just want to use that UITableView in different UIViews (say a UIView with a UILabel above the UITableView and one with a UILabel below the UITableView). 我有UITableView的行为按我想要的方式运行,我只想在不同的UIViews中使用UITableView(比如在UITableView上面有UILabel的UIView和在UITableView下面有UILabel的UIView)。

I know I can make a UIViewController that has an embedded UITableView in it and have the UIViewController act as the UITableView's delegate, but then I would have code reuse (the UITableViewController logic would be in multiple UIViewControllers). 我知道我可以创建一个UIViewController,其中包含一个嵌入式UITableView,并让UIViewController充当UITableView的委托,但后来我会重用代码(UITableViewController逻辑将在多个UIViewControllers中)。 Or am I looking at this problem the wrong way? 或者我是以错误的方式看待这个问题?

I want to somehow reuse the functionality of my UITableView in different UIViews. 我想以某种方式在不同的UIViews中重用我的UITableView的功能。

Thanks 谢谢

是的,你可以简单地在UIViewController中实例化(或获取引用)UITableViewController并调用这样的东西:

[self.view addSubview:tableViewController.tableView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM