NSLayoutManager and NSTextView problems
NSLayoutManager and NSTextView problems
- Subject: NSLayoutManager and NSTextView problems
- From: Rob Minerick <email@hidden>
- Date: Fri, 21 Nov 2003 14:11:20 -0600
What I'm trying to do is have a table which one can select different
entries and have the content of those entries show up in a text view,
similar to what Mail.app does. However, in addition to the content
showing up in the text view in the main window, I'd also like the
content to show up in a new window if the entry in the table view is
double clicked. So, I have no problem here, everything works as
expected when the entry is double clicked and the NSTextStorage
instance is shared between the two text views (one in the main window,
one in the newly created window). However, when I change the selection
in the table view and try to change the layoutManager of the main
window's NSTextView to use a new instance of NSTextStorage, I get the
following error (or similar, over and over):
*** Assertion failure in -[NSMutableRLEArray
objectAtIndex:effectiveRange:],
String.subproj/NSAttributedString.m:1009
Here is the pertinent part of what I'm doing to open a new window which
shares the NSTextStorage with the main window:
VMJournalEntryWindowController *wc = [[VMJournalEntryWindowController
alloc]
initWithWindowNibName:@"JournalEntryEditor"];
NSLayoutManager *mainLayoutManager = [[_ctl journalEntryTextView]
layoutManager], *layoutManager;
[wc showWindow:self];
wcTextStorage = [[wc entryTextView] textStorage];
wcLayoutManager = [[wc entryTextView] layoutManager];
[wcTextStorage beginEditing];
[wcTextStorage setAttributedString:RTFD];
[wcTextStorage endEditing];
[wcTextStorage addLayoutManager:mainLayoutManager];
RTFD is an NSMutableAttributedString which I left out for brevity, _ctl
is the main window's controller.
Then, when I change the selection in the table view, the following is
executed to point the main window to a different instance of
NSTextStorage:
NSTextStorage *sharedTextStorage = [[wc entryTextView] textStorage];
NSLayoutManager *mainLayoutManager = [[_ctl journalEntryTextView]
layoutManager];
NSTextStorage *newTS = [[NSTextStorage alloc] init];
[sharedTextStorage removeLayoutManager:mainLayoutManager];
[newTS addLayoutManager:mainLayoutManager];
wc is a pointer to the previously created editor, _ctl is the main
window's controller. This is being called from the NSTableView's
tableViewSelectionDidChange delegate.
I *must* be missing something about the interactions among the
different objects that make up the text architecture, but I've read and
re-read everything I can find in Apple's docs and the various books I
have - and I simply can't figure this out. Any ideas? Thanks...
--
Rob Minerick
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.