Re: Replacing NSTextView with custom view?
Re: Replacing NSTextView with custom view?
- Subject: Re: Replacing NSTextView with custom view?
- From: Peter Seibel <email@hidden>
- Date: Sat, 13 Jan 2007 22:51:40 -0800
On Jan 13, 2007, at 1:58 PM, Peter Seibel wrote:
On a related note, what's the easiest way to wire my own subclass
of NSTextStorage into a basic NSDocument based app (based on the
write a text editor in 15 minutes tutorial)? Since the NSTextView
that is instantiated in Interface Builder creates its
NSTextStorage under the covers, I can't figure out the best way to
intervene. Do I have to not create the NSTextView in IB and instead
create it programatically and add it to the scroll view at runtime?
So it turns out the best way to do this appears to be to create a
CustomView in IB and wrap it in a NSScrollView. Then set the class of
that CustomView to my own subclass of NSTextView that overrides
initWithFrame to instantiate the NSTextStorage subclass I want (along
with the NSLayoutManager and NSTextContainer) and then call
initWithFrame:textContainer. It's not sufficient to simply set a
custom class on the NSTextView you get from the palette since it will
be serialized and initialized via initWithCoder rather than
initWithFrame which doesn't give you a chance to call
initWithFrame:textContainer. At least that's my current
understanding. From there it was just a matter of jumping through a
few hoops in awakeFromNib to get my text view properly wired together
with the scroll view and it seems to be working. Thanks to the folks
on #macdev for their help.
-Peter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden