As it becomes common for my recent posts, since the issue is not easy to
explain in words, I’ve attached a very simple project demonstrating it.
It’s ongoing troubles with NSSplitViews, this time specifically with
NSSplitViewController. A sentence from documentation says:
“A split view controller employs lazy loading of its views. For example, adding
a collapsed split view item as a new child does not load the associated view
until it is revealed.”
I can get this to work (in both code and IB) only when setting an instance of
NSSplitViewController as a contentViewController of a window. But I can’t get
NSSplitViewController to load NSSplitViewItems otherwise.
In the attached project there are two split view controllers; one is set as the
content view controller of a window and it properly loads its split view items,
one created with instance of custom subclass named LeftViewController and the
other with an instance of another subclass named RightViewController. However,
the view property of the RightViewController contains a subview, in which I try
to add split view controlled by another split view controller. I do it in
RightViewController’s -viewDidLoad method and the code looks like this:
- (void)viewDidLoad
{
NSLog(@"-[%@ viewDidLoad]", self);
[self setSplitViewController:[[NSSplitViewController alloc]
initWithNibName:nil bundle:nil]];
NSSplitView *splitView = [[self splitViewController] splitView];
[[self containerView] addSubview:splitView];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"|-0-[splitView]-0-|" options:0 metrics:nil
views:NSDictionaryOfVariableBindings(splitView)]];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:|-0-[splitView]-0-|" options:0 metrics:nil
views:NSDictionaryOfVariableBindings(splitView)]];
NSViewController *viewController = [[RightLeftViewController alloc]
initWithNibName:nil bundle:nil];
[self addChildViewController:viewController];
NSSplitViewItem *splitViewItem = [NSSplitViewItem
splitViewItemWithViewController:viewController];
[[self splitViewController] addSplitViewItem:splitViewItem];
viewController = [[RightRightViewController alloc] initWithNibName:nil
bundle:nil];
[self addChildViewController:viewController];
splitViewItem = [NSSplitViewItem
splitViewItemWithViewController:viewController];
[[self splitViewController] addSplitViewItem:splitViewItem];
}
However, even though that inner split view is added into the split view
hierarchy, its controlling split view controller doesn’t load added split view
items (created with instances of yet another two subclasses
RightLeftViewController and RightRightViewController). Those two view
controllers (RightLeft and RightRight) never reach their respective
-viewDidLoad methods. Adding “inner” view controllers as “outer” view
controller children doesn’t make any difference.
It’s all in the project and it’s pretty simple. You can download it at
https://www.dropbox.com/s/8w0k2of88n1ksvw/SplitViewControllerTest.zip?dl=0
I’d appreciate any help and explanation why this doesn’t work. Thanks in
advance.
-- Dragan
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]