简体   繁体   English

如何使UITableView追溯成为UIView的子视图?

[英]How can you make UITableView a subview of UIView retrospectively?

I have a view controller (subclass of UIViewController, not UITableViewController), with a table view as a subview. 我有一个视图控制器(UIViewController的子类,而不是UITableViewController),并将表视图作为子视图。 I now want to put another view on that screen, but can't resize the table view to not take up the entire screen, or drag in a view above that. 我现在想在该屏幕上放置另一个视图,但是无法调整表格视图的大小以不占据整个屏幕,也不能在该视图上方拖动一个视图。 It seems that the view can only contain a single table view. 该视图似乎只能包含一个表视图。 I know it's possible to have a table view and other views within the same screen, so what am i missing here? 我知道在同一屏幕上可以有表格视图和其他视图,所以我在这里错过了什么?

在此处输入图片说明

Take a look at your view hierarchy on left - your view is subview of tableView . 看一下左侧的视图层次结构-您的viewtableView子视图。 And you need to have something like 你需要有类似的东西

ViewController.view
               |--> view
               |--> tableView

And you have 你有

ViewController.tableView
               |--> view

Edit 编辑

What should you do 你该怎么办

  1. Copy (Cmd-C) your Table view. 复制(Cmd-C)您的表格视图。 Than delete it 比删除它 清洁控制器

  2. Drag View to your View Controller 将View拖到您的View Controller

仅根视图

  1. Choose View and paste Table view to it (Cmd-V) 选择“视图”并将其粘贴到表视图(Cmd-V) 带有子视图的表视图

  2. Drag View from Table view upwards to root view of Controller 从表视图向上拖动视图到Controller的根视图 正是您想要的

Now, you can position your view and table view however you want 现在,您可以根据需要定位视图和表格视图

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

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