简体   繁体   English

添加tableview作为子视图查看?

[英]Add tableview as subview to view?

I would like to add a table view to a view in interface builder and then be able to control that table view from a table view controller.我想将表视图添加到界面生成器中的视图,然后能够从表视图 controller 控制该表视图。

I can add the table with IB without any troubles, but how can I link the table view with a table view controller?我可以毫无问题地使用 IB 添加表格,但是如何将表格视图与表格视图 controller 链接?

In your IB file insert 2 objects: UITableView (as subview) and UITableViewController subclass (as an object).在您的 IB 文件中插入 2 个对象: UITableView (作为子视图)和UITableViewController子类(作为对象)。 Set datasource and delegate outlets and you are ready to go: :)设置datasourcedelegate出口,您就可以准备好 go ::)

As an alternative, you can add the UITableView to your view and control it from within your UIViewController subclass.作为替代方案,您可以将 UITableView 添加到您的视图中,并从您的 UIViewController 子类中控制它。 You then just need to conform to the UITableViewDataSource and UITAbleView delegate protocols, on top of what Andrew already mentioned.然后,您只需遵守 Andrew 已经提到的 UITableViewDataSource 和 UITAbleView 委托协议。

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

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