Re: Changing up/down arrow behavior for NSTextField
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