• 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: Formatters and TextViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Formatters and TextViews


  • Subject: Re: Formatters and TextViews
  • From: Douglas Davidson <email@hidden>
  • Date: Mon, 10 Sep 2001 11:45:27 -0700

On Sunday, September 9, 2001, at 10:36 AM, Rob Rix wrote:

Looking through the NSFormatter docs, I see that it is used in conjunction with an NSCell. Well, I need to use an NSFormatter with an NSTextView. Is there any way I can associate them? Perhaps putting an NSTextView into an NSCell or something?

The uses of NSFormatter with NSCell are implemented using NSTextView delegate methods such as

- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;

and it should be possible for you to implement methods like this yourself, and either communicate with your formatter or else just put the relevant code into your textview's delegate. You may not need all of the functionality that NSCell and NSFormatter provide; for example, if you merely need to be notified of changes, rather than to approve or modify them, you may be able to use

- (void)textDidChange:(NSNotification *)notification;

instead (defined in the superclass, in NSText.h).


To handle links in an NSTextView, assign the relevant range the attribute NSLinkAttributeName with some appropriate value. When the user clicks in this range, the NSTextView will have its method

- (void)clickedOnLink:(id)link atIndex:(unsigned)charIndex;

called, which will first try to call the delegate method (if implemented)

- (BOOL)textView:(NSTextView *)textView clickedOnLink:(id)link atIndex:(unsigned)charIndex;

If that method is not implemented or returns NO, then it will try to interpret the value of the link attribute as an NSURL or as an NSString whose contents represent an URL, and if successful it will try to open that URL.

If you use something other than absolute URLs as the values of your NSLinkAttributeName, or if you want to do the opening yourself, then you will probably need to implement the delegate method.

Douglas Davidson


  • Follow-Ups:
    • Re: Formatters and TextViews
      • From: Rob Rix <email@hidden>
References: 
 >Formatters and TextViews (From: Rob Rix <email@hidden>)

  • Prev by Date: Re: Question about a warning in code...
  • Next by Date: Re: Question about a warning in code...
  • Previous by thread: Formatters and TextViews
  • Next by thread: Re: Formatters and TextViews
  • Index(es):
    • Date
    • Thread