Answer to my own question:

The baselineOffsetFromBottom seems to be cached by (or in combination with) the 
corresponding NSLayoutConstraint instance that uses it.
When I remove the constraint from its NSView and add it again, then 
baselineOffsetFromBottom is called again. But I found no other way to force the 
Autolayout system to read the baselineOffsetFromBottom again other than 
removing and re-adding the relevant constraint.
It seems I should file a bug. But at least I found a workaround.

Regards,
Mani

> Hi,
> 
> I have a view hierarchy using Cocoa Autolayout (new in Lion) loaded from a 
> nib.
> After the nib is loaded, I do some additional configuration for some views 
> (mostly in awakeFromNib). Specifically I have a NSTextField subclass and the 
> additional configuration causes my custom baselineOffsetFromBottom 
> implementation to return a different value. Problem: Cocoa only calls 
> baselineOffsetFromBottom when initially loading the nib, but never calls it 
> again! The value seems to be cached somehow by the Cocoa Autolayout system. 
> So my custom NSTextField subclass with baseline autolayout constaints is not 
> correctly aligned, because an outdated value is used.
> How can I force Cocoa to re-read baselineOffsetFromBottom?
> 
> I tried calling setNeedsUpdateConstraints:YES, setNeedsLayout:YES and 
> invalidateIntrinsicContentSize on my custom text field. I called 
> layoutIfNeeded on the window. Nothing helps! baselineOffsetFromBottom is 
> never called again and the layout is always done with the old outdated value.
> I even tried setting a different font to the text field. That should normally 
> "reset" the baseline offset and force re-calling baselineOffsetFromBottom, 
> even in a plain "not subclassed" NSTextField, shouldn't it? But even that 
> does not force re-calling baselineOffsetFromBottom; so this smells like a bug.
> I put a breakpoint (and an NSLog) in my baselineOffsetFromBottom 
> implementation, and I see that it is really called just once while initially 
> loading the nib and I can't force it to be called again.
> 
> Any other ideas?
> Is this a bug in Cocoa?
> 
> Regards,
> Mani
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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/lists%40mani.de
> 
> This email sent to li...@mani.de


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to