Try changing the container size once the layout is complete, you can do this by using the delegate method: - (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag
and checking the layoutFinishedFlag.

In my experience it is not safe to do anything that can trigger layout in the "didCompleteLayoutForTextContainer" delegate method. This is unfortunately just one of a few ways in which the layout system seems to be fragile. The rules I've come to live by:

1. Never trigger recursive layout. This means that if there is any NSLayoutManager code below you on the stack, you cannot safely:
        a. invalidate layout for any characters/glyphs.
        b. change geometry for a text container.
c. request layout information for an unfinished region, unless you use the "withoutAdditionalLayout:YES" flag.

2. As Rimas discovered, do not trigger layout before NSTextStorage has completely cleared its edited state.

3. Never edit the contents of the NSTextStorage while layout is active on the stack.

To my knowledge these aren't really documented anywhere, excluding #3 which is sort of mentioned in the documentation for -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:]. Unfortunately these issues make it very awkward to do many of the things one might want in response to delegate/notification methods. Basically you just have to queue up your changes until you know layout/editing isn't in progress.

~Martin

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to