NSView in autolayout not displayed

I am working on an application in MacOSX I am using autolayout. There I have a custom NSView with two subviews.

In my custom NSView I am creating constraints like this:


|[subview1(subview1Width)][subview2(subview2Width)]|


And same for vertical constraints

Then I set the constraints of my NSView like this:


[anotherView][MyNSView]


But I do not why I don't see MyNSView displayed.

I have overriden

- (CGSize)intrinsicContentSize
method to return the witdh that I want my NSView to have and I am also calling method

[MyNSview invalidateIntrinsicContentSize] to force Cocoa to get the intrinsic size but no success

I can't use fixed witdth for MyNsView because it will be enlarged/shortened depending on the visibility of the subviews.

Can someone tell me what I am doing wrong?

Thanks

Replies

If you're specifying the width / height of your subviews explicitly using constraints (as shown in your example VFL string) then you shouldn't override instrinsicContentSize. Auto layout can calculate the size from the constraints.


As to why your view isn't showing. What is its frame at runtime? (You can use Xcode's view debugger to check that, or plain old NSLog in layoutSubviews). Is it contained in another view that is clipping its subviews?

Do you mean that if I set fixed width in my subviews, it is pointless to override intrinsicContentSize?

I have overriden layout method in MyNSView and it is returning 0 width but I don't know what is causing that ....