Hi, I have purpose to display few View from different NSViewControllers on one ViewController.
For such purpose I create one controller and on required moment replace View with new one from another VIewController.
On Main (Always exist, at least for current scope) controller I have RootView (View from NSViewController) and PresentingView(Subview on View from NSViewController). All works fine, except if I change View twice or so... I can't figure out where is the problem.
What I use:
Category for AddSubview:
[Category(typeof(NSView))]
public static class NSViewSubviewExtension
{
public static void AddSubviewWithConstaint(this NSView parentView, NSView view)
{
ArgumentValidator.NotNull(view, () => view);
ArgumentValidator.NotNull(parentView, () => parentView);
view.TranslatesAutoresizingMaskIntoConstraints = false;
parentView.AddSubview(view);
var topConstaint = NSLayoutConstraint.Create(view, NSLayoutAttribute.Top, NSLayoutRelation.Equal, parentView, NSLayoutAttribute.Top, 1, 0);
var bottomConstaint = NSLayoutConstraint.Create(view, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, parentView, NSLayoutAttribute.Bottom, 1, 0);
var leadingConstaint = NSLayoutConstraint.Create(view, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, parentView, NSLayoutAttribute.Leading, 1, 0);
var trailingConstaint = NSLayoutConstraint.Create(view, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, parentView, NSLayoutAttribute.Trailing, 1, 0);
NSLayoutConstraint[] allConstaints =
{
topConstaint, bottomConstaint, leadingConstaint, trailingConstaint
};
parentView.AddConstraints(allConstaints);
}
}
And method for replaceView
protected void ReplaceView(NSViewController viewController)
{
if (this.rightContentViewController != null)
//this.rightContentViewController - tempCreatedViewController from which i take View
{
this.rightContentViewController.View.RemoveFromSuperview();
}
foreach (NSView obj in this.splitContentHolder.RightHolderView.Subviews)
//this.splitContentHolder - MainViewController
//this.splitContentHolder.RightHolderView - presentingView
{
obj.RemoveFromSuperview();
}
this.rightContentViewController = viewController;
this.splitContentHolder.RightHolderView.AddSubviewWithConstaint(viewController.View);
}
Also
- all operation on main thread
- layoutSubiew and other similar methds not help
- frame is correct
if I check in console - all object added as expected:
- > this.splitContentHolder.RightHolderView.Subviews
{AppKit.NSView[1]}
[0]: {}
- > this.splitContentHolder.RightHolderView.Subviews
but i see previous "freezed" NSView from prevViewController - looks like it's not redrawed
- when i resize View - everything become white (as bg color of presenting View)
Can someone advice - why I cant change subview more that few times?