• 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: Duncan Champney <email@hidden>
  • Date: Thu, 14 Feb 2008 10:14:29 -0500


On Feb 14, 2008, at 9:53 AM, glenn andreas wrote:


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






Glenn,

I gather my code works because a selector happens to contain the method name at the beginning, but I should not assume that? I certainly don't want to write my code based on internal structures that may not work in future releases. Thanks for the warning, and the safer way of doing it.


Duncan _______________________________________________


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

  • Prev by Date: Re: single vs multiple NIBs
  • Next by Date: logging object creations and destructions
  • Previous by thread: Re: Changing up/down arrow behavior for NSTextField
  • Next by thread: [Q] NSXMLDocument & TidyHTML on Leopard
  • Index(es):
    • Date
    • Thread