Identifying NSTextViews
Identifying NSTextViews
- Subject: Identifying NSTextViews
- From: Rippit the Ogg Frog <email@hidden>
- Date: Tue, 28 Jul 2009 20:56:47 -0700
How can one identify which of several NSTextViews has a given piece of
text in it?
I have a window with six NSTextViews. I made the window's controller
the delegate for each of them - or rather for their NSText base class.
My delegate's -textDidChange method gets called whenever the user edits
any of the views, and I can get the text like this:
- (void) textDidChange: (NSNotification*) notification
{
NSString *text = [[notification object] string];
// But which view was it?
return;
}
If my text items were NSTextFields rather than NSTextViews, I could set
a tag for each of them and check the tag in -textDidChange. But
NSTextViews don't have tags. NSTextFields have tags because they
subclass NSControl, but NSTextView isn't a subclass of NSControl.
I need to use views and not fields so they can have scrollbars and allow
multiple lines of text.
One way I could do it would be to subclass NSTextView and implement -tag
and -setTag in my subclass. But that seems like a lot of trouble to go
to for what must be a very common problem. Surely there is a better way.
In the list archives I saw a mention of creating a separate outlet in
the controller for each NSTextView, with each view being connected to a
separate outlet. I think that would work fine for me but I don't quite
understand how to go about it - I haven't done much Cocoa programming
before.
My objective is just to capture the text from each view when the window
is dismissed, so there could be another way to do what I want without
using a delegate. It's not necessary for me to get called for every
character the user types.
Thanks!
--
Rippit the Ogg Frog
email@hidden
http://www.oggfrog.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden