determine which NSTextView is sending to delegate?
-
Is there a way to use IB to mark a NSTextView in some way so that the
info can be retrieved by the delegate to determine which view is
sending the message. (in my case "textDidEndEditing"). I could
subclass but it seems this should be a common task and settable in IB.
all the demos I can find only have one NSTextView.
I tried to check the title of its container view (NSBox). but that
does not seem to respond to '-title' message. Maybe I am not getting
the container object correctly:
-(void) textDidEndEditing:(NSNotification *) notification
{
NSText* tx = [notification object];
NSView* view = [notification object];
NSView* sview = [view superview];
NSBox* box = (NSBox*)sview;
NSString* title = [box title]; <--- debugger seems to leave here
...
}
Thanks for Help
John -
On Nov 5, 2004, at 12:57 PM, John James wrote:> Is there a way to use IB to mark a NSTextView in some way so that the
> info can be retrieved by the delegate to determine which view is
> sending the message. (in my case "textDidEndEditing"). I could
> subclass but it seems this should be a common task and settable in IB.
>
> all the demos I can find only have one NSTextView.
>
> I tried to check the title of its container view (NSBox). but that
> does not seem to respond to '-title' message. Maybe I am not getting
> the container object correctly:
>
> -(void) textDidEndEditing:(NSNotification *) notification
> {
> NSText* tx = [notification object];
> NSView* view = [notification object];
> NSView* sview = [view superview];
> NSBox* box = (NSBox*)sview;
> NSString* title = [box title]; <--- debugger seems to leave here
> ...
> }
a NSBox contains a NSView which contains the other views.
----- -
On 5 Nov 2004, at 22:27, John James wrote:> s there a way to use IB to mark a NSTextView in some way so that the
> info can be retrieved by the delegate to determine which view is
> sending the message. (in my case "textDidEndEditing"). I could
> subclass but it seems this should be a common task and settable in IB.
If your object is in IB, make outlets and connect them to the text
views. Then when you receive the notification, you can just check if
the notification object is any of the text views.
Jonathon Mah
<me...> -
At 5:40 AM -0800 11/5/04, <cocoa-dev-request...> wrote:> From: Jonathon Mah <me...>
> Date: Sat, 6 Nov 2004 00:09:19 +1030
>
> On 5 Nov 2004, at 22:27, John James wrote:
>
>> s there a way to use IB to mark a NSTextView in some way so that the info can be retrieved by the delegate to determine which view is sending the message. (in my case "textDidEndEditing"). I could subclass but it seems this should be a common task and settable in IB.
>
> If your object is in IB, make outlets and connect them to the text views. Then when you receive the notification, you can just check if the notification object is any of the text views.
I find that setting each view to a different tag value is easier, and you can check them in a switch statement instead of a long list of if/then/else lines...
--
Rainer Brockerhoff <rainer...>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php -
This is what I was looking for. But -setTag does not seem to be
available on a NSTextView or rather NSView. According to the
documentation you must subclass to set the tag.
NSView: tag
- (int)tag
Returns the receiverâs tag, an integer that you can use to identify
view objects in your application. NSViewâs implementation returns â1.
Subclasses can override this method to provide individual tags,
possibly adding storage and a setTag: method (which NSView doesnât
define).
I see no mention of tag in NSTextView.
Maybe there is something I missed?
Now I have switched to a set of NSTableView's which allows setting the
tag value in IB allowing me to use the switch as you suggested. (My
app could really use the table instead of requiring me to parse the
text to get the values I want.)
So all is well.
Thanks
On Nov 5, 2004, at 9:46 AM, Rainer Brockerhoff wrote:>
> I find that setting each view to a different tag value is easier, and
> you can check them in a switch statement instead of a long list of
> if/then/else lines...
>
> -- -
At 9:30 AM -0500 11/6/04, John James wrote:> This is what I was looking for. But -setTag does not seem to be available on a NSTextView or rather NSView. According to the documentation you must subclass to set the tag.
> NSView: tag
> - (int)tag
> Returns the receiver's tag, an integer that you can use to identify view objects in your application. NSView's implementation returns -1. Subclasses can override this method to provide individual tags, possibly adding storage and a setTag: method (which NSView doesn't define).
>
> I see no mention of tag in NSTextView.
>
> Maybe there is something I missed?
>
> Now I have switched to a set of NSTableView's which allows setting the tag value in IB allowing me to use the switch as you suggested. (My app could really use the table instead of requiring me to parse the text to get the values I want.)
Oops; my fault. I somehow thought you were saying NSTextField - which, being a NSControl, has tags implemented.
I often find tags so useful that I implement them in my subclasses if they're not already available...
--
Rainer Brockerhoff <rainer...>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php


