Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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/1/cocoa/3.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
Objective c xib文件中的AddSubView包含两个或多个自定义视图_Objective C_Cocoa_Addsubview - Fatal编程技术网

Objective c xib文件中的AddSubView包含两个或多个自定义视图

Objective c xib文件中的AddSubView包含两个或多个自定义视图,objective-c,cocoa,addsubview,Objective C,Cocoa,Addsubview,我有两个CustomView(NSView*one,NSView*two)的xib,如何在AppDelegate中添加子视图 self.content = [[ContentViewController alloc] initWithNibName:@"ContentViewController" bundle:nil]; [[[[self vertical] subviews] objectAtIndex:1] addSubvie

我有两个
CustomView
NSView*one,NSView*two)的
xib
,如何在
AppDelegate
中添加子视图

self.content = [[ContentViewController alloc]
                initWithNibName:@"ContentViewController"
                bundle:nil];
[[[[self vertical] subviews] objectAtIndex:1] addSubview:[_content one]];

这种方法不起作用。

每个视图都应该在它自己的NIB文件中,因为
NSViewController
只有一个
视图
实例变量

因此,答案是将每个视图拆分为自己的NIB;正确设置自定义类,然后将文件所有者设置为
NSViewContoller
,并将
视图从控制器连接到自定义视图


然后分别加载每个视图,并根据需要添加它们的视图(注意保留对用于加载视图的
NSViewController
的引用)。

感谢您的详细回复。