Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 向容器视图添加多个视图_Ios_Objective C_Uitableview_Uiviewcontroller_Uicontainerview - Fatal编程技术网

Ios 向容器视图添加多个视图

Ios 向容器视图添加多个视图,ios,objective-c,uitableview,uiviewcontroller,uicontainerview,Ios,Objective C,Uitableview,Uiviewcontroller,Uicontainerview,我正在考虑向现有的UI视图控制器添加许多TableView 我看到了我注定要走的路 但是,我的问题是,我可以将多个TableView嵌入到单个ContainerView吗? 我的应用程序做了各种各样的测试,都有结果。在每个测试完成后,我想添加一个TableView,以便它们整齐地显示在彼此下面 这可能吗?是的,你可以。你可以做两件事: 一个视图控制器-多个表视图(作为根视图的子视图) 或 一个容器控制器-使用VC容器的多个ChildViewController(每个都有一个表视图) 这是您可以在

我正在考虑向现有的UI视图控制器添加许多TableView

我看到了我注定要走的路

但是,我的问题是,我可以将多个TableView嵌入到单个ContainerView吗?

我的应用程序做了各种各样的测试,都有结果。在每个测试完成后,我想添加一个TableView,以便它们整齐地显示在彼此下面


这可能吗?是的,你可以。你可以做两件事:

一个视图控制器-多个表视图(作为根视图的子视图)

一个容器控制器-使用VC容器的多个ChildViewController(每个都有一个表视图)


这是您可以在ViewDidLoad中为UIViewController子类执行的操作

// Do any additional setup after loading the view, typically from a nib.

CGRect frame = self.view.frame;

// this container shall hold the two tables that I am going to add later
// container shall share the same size as view controller's "view"
UIView *container = [[UIView alloc] initWithFrame:frame];

frame.size.height = frame.size.height / 2; // I want to fit two table view vertically to cover the container view

UITableView *tableView1 = [[UITableView alloc] initWithFrame:frame];
tableView1.backgroundColor = [UIColor redColor];
// ...
// ...
// Assign more table view properties here
// ...
// ...
[container addSubview:tableView1];

frame.origin.y = frame.size.height; // update coordinates for the second table view

UITableView *tableView2 = [[UITableView alloc] initWithFrame:frame];
tableView2.backgroundColor = [UIColor greenColor];
// ...
// ...
// Assign more table view properties here
// ...
// ...
[container addSubview:tableView2];

[self.view addSubview:container];

您必须为所有TableView设置代理,以使其正常工作,但这将为您提供一些帮助。(我添加了一些不同的背景色来区分两个表视图)

容器视图是什么意思?有一个容器视图控制器..这是一个特定的东西..但没有特殊的容器视图..任何标准的UIView在实践中都可以是容器视图。我在这个问题中尝试了更多的解释:当我寻求帮助以最佳方式接近某事物时,给出负票有点苛刻..拥有负票到底有什么意义那个容器视图?这是多余的,毫无用处。另外,frame.origin.y=frame.size.height;//更新第二个表视图的坐标-将失败,因为您无法设置struct的成员,您需要创建一个新的。frame.origin.y=frame.size.height;不会失败,因为frame是一个局部变量。你可以离开容器视图,直接添加到self.view,如果你愿意的话,只是为了澄清如何将多个视图添加到一个容器中。我想,我很久以前就完成了框架。显然,UIView以某种方式保护了结构成员8-/谢谢你,先生,你是对的:)这就是我到目前为止所拥有的:你能看看并告诉我我哪里出了问题吗?感谢@Gavin Bunney正确回答了这个问题。它和这个有什么关系吗?