• 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: Click to edit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Click to edit


  • Subject: Re: Click to edit
  • From: Stefan Arentz <email@hidden>
  • Date: Sun, 13 Jul 2008 10:45:08 -0400


On Jul 13, 2008, at 12:46 AM, Jens Alfke wrote:


On 12 Jul '08, at 7:50 PM, Stefan Arentz wrote:

I would like to use text labels that turn into editable text fields when you click them. Like Address Book has when you edit an address card. Does anyone know how those work? Is it a matter of flipping the editable property or are those custom controls?

You can implement a text field like that fairly easily; I have one that's a subclass of NSTextField overriding two methods (see below).


What Address Book does is a different matter. The card is, I believe, a single NSTextView with some tricky delegate methods that control what ranges of the text are editable and selectable.

—Jens

- (void) mouseDown: (NSEvent*)event
{
   if( ! [self isEditable] ) {
       [self setBezeled: YES];
       [self setDrawsBackground: YES];
       [self setEditable: YES];
       self.frame = NSInsetRect(self.frame, -2, -3);
       [self.window makeFirstResponder: self];
   }
}

- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
{
   if( [self isEditable] ) {
       [self setEditable: NO];
       [self setDrawsBackground: NO];
       [self setBezeled: NO];
       self.frame = NSInsetRect(self.frame, 2, 3);
   }
   return [super sendAction: theAction to: theTarget];
}

Thanks Jens. That looks like a good start.

I did remember where I found some more 'official' code now btw. It was part of a Cocoa Techniques session at WWDC 2003. I did attend that WWDC but I can't find that code in my ADC account anymore. I guess it is too old. Does anyone still have a copy of that code? Or was it ever put on a developer DVD?

 S.

_______________________________________________

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


References: 
 >Click to edit (From: Stefan Arentz <email@hidden>)
 >Re: Click to edit (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Trigonometric Problem, Particularly tan() Function
  • Next by Date: Re: Trigonometric Problem, Particularly tan() Function
  • Previous by thread: Re: Click to edit
  • Next by thread: Trigonometric Problem, Particularly tan() Function
  • Index(es):
    • Date
    • Thread