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
的引用)。感谢您的详细回复。