On Feb 5, 2013, at 6:03 PM, Keary Suska wrote: > I have a custom view on which I place multiple NSTextViews, but when printed > only the *content* last NSTextView placed actually shows up. That is, to make > sure I am placing view appropriately my NSTextView subclass draws a box > around its bounds. The box shows up, but no text inside even though I can > verify that the text storage has content. > > I have to construct everything manually since I may need multiple NSTextViews > for a single NSTextStorage: > > - (void)addLetter:(NSTextStorage *)letter mergeData:(NSDictionary *)data > { > // copy letter & merge > [textStorage release]; > textStorage = [[NSTextStorage alloc] initWithAttributedString:letter];
I have solved my issue, which revealed a perhaps little-known memory management issue that may benefit someone else so I post here for posterity. The issue is in the above lines, where I release the NSTextStorage. I was assuming that the NSTextView would retain the text storage, which certainly must be the case in certain situations, but clearly isn't the case when one is constructing the text system by hand. I.e., when you let NSTextView construct its own text system, it retains the related objects, but when you use the -initWithFrame:textContainer: method, it does not. Furthermore, for some behind-the-scenes reason, when the NSTextStorage is deallocated it actually nils the properties of the NSTextView instead of letting them be invalid and crashing (which would be more expected). More clearly, the textStorage, layoutManager, and textContainer properties of NSTextView are set to nil when the NSTextStorage is deallocated. Anyway, keeping the NSTextStorage objects around for the printing process solved the issue. I hope someone else may benefit from my pain ;-) Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" _______________________________________________ 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