Lee Twelve
Lee Twelve

Reputation: 65

addSubviews from xib file contain two or more Custom View

I have xib with two CustomView (NSView *one, NSView *two),how i addSubview in AppDelegate?

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

This way don't work.

Upvotes: 1

Views: 123

Answers (1)

trojanfoe
trojanfoe

Reputation: 122391

Each view should be in it's own NIB file, as the NSViewController only has a single view instance variable.

So the answer is to split each view into it's own NIB; set the custom class correctly and then set the File Owner to NSViewContoller and connect the view from the controller to the custom view.

You then load each separately and add their views whereever you like (taking care to keep a reference to the NSViewController used to load the view).

Upvotes: 3

Related Questions