将TableView中的TableView嵌入到另一个视图中 [英] Embedding TableView in TableViewController into another view

查看:159
本文介绍了将TableView中的TableView嵌入到另一个视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义表视图控制器的内容(添加一些按钮等),但是其根视图是表视图.是否可以将其嵌入到另一个视图中并在其上添加控件?

I would like to customize content of table view controller(add some buttons, etc.) but root view for that is table view. Is it a way to embed it into another view and add controls on it?

推荐答案

您可以使用容器视图.

在情节提要中创建另一个将用于承载这些控件的视图控制器.然后从 Object Library (通常是列表中的最后一项)中拖入 Container View (容器视图),并将其放置在您希望表格视图出现的位置(可能是整个屏幕) ).这样做,容器视图将创建另一个视图控制器.只需将其删除,然后将ctrl容器视图拖动到表格视图控制器,然后选择 embed segue.

In the storyboard create another view controller that you would use to host those controls. Then drag in Container View from the Object Library (normally the last item in the list) and place it where you want the table view to appear (which could be the whole screen). Doing this, the Container View will create another view controller. Simply delete that and ctrl drag from the Container View to your table view controller and select embed segue.

这样做,如果它不依赖其他视图控制器为其提供数据以使其正常工作,则不必在当前表视图控制器中进行任何更改.但是,如果确实如此,则可以将Segue标识符分配给嵌入式 Segue,实现prepareForSegue:sender:并执行通常对其他Segue所做的任何事情.

By doing this, you would not have to change anything in your current table view controller if it doesn't depend on other view controllers to give it data in order for it to work. If it does, however, you could assign the segue identifier to the embed segue, implement prepareForSegue:sender: and do whatever you would normally do with other segues.

这篇关于将TableView中的TableView嵌入到另一个视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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