• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Identifying NSTextViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Identifying NSTextViews


  • Subject: Re: Identifying NSTextViews
  • From: Andy Lee <email@hidden>
  • Date: Wed, 29 Jul 2009 00:16:13 -0400

On Jul 28, 2009, at 11:56 PM, Rippit the Ogg Frog wrote:
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;
}

As others have pointed out, [notification object] *is* the text view in question. This is a general pattern -- delegate methods are passed the thing they are a delegate for, and this is one reason. *But* this is not the delegate method you want to implement...


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.

In the header of your window controller class, declare instance variables like this:


    IBOutlet NSTextView * textViewOne;
    IBOutlet NSTextView * textViewTwo;
    ... etc. ...

Save the file and return to Interface Builder. The new outlets will show up and you'll be able to make connections from your window controller to the various text views.

==> NOTE: make sure to connect to the text views and not the scroll views that enclose them.

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.

Implement the window delegate method windowWillClose:. Your window controller is probably already the window's delegate, but if it isn't, make that connection in IB. Then in windowWillClose:, collect the data from your six text views using [textViewOne string], [textViewTwo string], etc.


--Andy


_______________________________________________

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


  • Follow-Ups:
    • Re: Identifying NSTextViews
      • From: Rippit the Ogg Frog <email@hidden>
    • Re: Identifying NSTextViews
      • From: Rippit the Ogg Frog <email@hidden>
References: 
 >Identifying NSTextViews (From: Rippit the Ogg Frog <email@hidden>)

  • Prev by Date: Re: Identifying NSTextViews
  • Next by Date: NSRulerView Centimeters [Solved]
  • Previous by thread: Re: Identifying NSTextViews
  • Next by thread: Re: Identifying NSTextViews
  • Index(es):
    • Date
    • Thread