• 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
Preventing textfield in table from clicking default button
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Preventing textfield in table from clicking default button


  • Subject: Preventing textfield in table from clicking default button
  • From: Seth Willits <email@hidden>
  • Date: Sat, 16 Aug 2014 19:53:19 -0700


When editing in a NSTextField and return is pressed, it fires the text field's action and also sends performKeyEquivalent: to the window, which clicks the default button. Usually that's just fine, but in the case where a view-based table view has editable NSTextFields in it, this makes no sense.

Anybody figured out how to prevent this?



---


It happens in NSTextField textDidEndEditing, so there's no stopping performKeyEquivalent: from being called short of subclassing NSTextField and reimplementing that method. (Eww)

You also can't disable the key equivalent on the button in controlTextDidBeginEditing and re-enable it in controlTextDidEndEditing, because the performKeyEquivalent: is called after the controlTextDidEndEditing notification is sent.

I thought maybe I could so some light NSTExtField subclassing and use NSWindow's disableKeyEquivalentForDefaultButtonCell...

@implementation MyTableCellTextField

- (void)textDidBeginEditing:(NSNotification *)notification;
{
	[self.window disableKeyEquivalentForDefaultButtonCell];
	[super textDidBeginEditing:notification];
}

- (void)textDidEndEditing:(NSNotification *)notification;
{
	[super textDidEndEditing:notification];
	[self.window enableKeyEquivalentForDefaultButtonCell];
}

@end


Sadly, that doesn't work. My default button is still clicked when [super textDidEndEditing:] calls performKeyEquivalent:, despite the defaultButtonCell being the right button… As a matter of fact, looking at the implementation of those NSWindow methods shows they're identical to each other… which makes absolutely no sense. So obviously that doesn't do what one would expect.



This is leaving me little choice but to do something very specialized and ugly.

Am I missing something?


--
Seth Willits




_______________________________________________

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: Preventing textfield in table from clicking default button
      • From: Ken Thomases <email@hidden>
    • Re: Preventing textfield in table from clicking default button
      • From: Seth Willits <email@hidden>
  • Prev by Date: Re: Class in Swift
  • Next by Date: Re: Preventing textfield in table from clicking default button
  • Previous by thread: Re: Class in Swift
  • Next by thread: Re: Preventing textfield in table from clicking default button
  • Index(es):
    • Date
    • Thread