• 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: Changing up/down arrow behavior for NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing up/down arrow behavior for NSTextField


  • Subject: Re: Changing up/down arrow behavior for NSTextField
  • From: glenn andreas <email@hidden>
  • Date: Thu, 14 Feb 2008 08:53:49 -0600


On Feb 14, 2008, at 8:44 AM, Duncan Champney wrote:
Happily, the keystrokes I want to special-case, up/down arrow and shift up/down arrow, have existing command selectors ("moveUp", "moveDown", "moveUpAndModifySelection", and "moveDownAndModifySelection"). I wrote my code to handle those 4 messages, and ignore others. Rather than using "- tryToPerform:aSelector", I just do a string match on the different command selectors, like this:

  NSLog(@"Command = %s", command);
  if (!strcmp((char *)command, "moveUp:"))
      //handle up arrow


This is very wrong - it just happens to work for you (due to the way it just happens to be implemented internally)

command is a selector (SEL) which is _not_ a (char *), and you shouldn't compare selectors using strcmp.

The solution is actually much cleaner and simpler:

	NSLog(@"Command = %@", NSStringFromSelector(command));
	if (command == @selector(moveUp:)) {
		// handle up arrow
	....



Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next generation of fractal art




_______________________________________________

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: Changing up/down arrow behavior for NSTextField
      • From: Duncan Champney <email@hidden>
References: 
 >Re: Changing up/down arrow behavior for NSTextField (From: Duncan Champney <email@hidden>)

  • Prev by Date: Re: Changing up/down arrow behavior for NSTextField
  • Next by Date: single vs multiple NIBs
  • Previous by thread: Re: Changing up/down arrow behavior for NSTextField
  • Next by thread: Re: Changing up/down arrow behavior for NSTextField
  • Index(es):
    • Date
    • Thread