• 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: SEL and NSSelectorFromString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SEL and NSSelectorFromString


  • Subject: Re: SEL and NSSelectorFromString
  • From: Ondra Cada <email@hidden>
  • Date: Sun, 20 Jan 2002 17:57:16 +0100

Jason,

>>>>>> Jason Blake (JB) wrote at Sat, 19 Jan 2002 20:12:57 -0600:
JB> I can't find much documentation for what SEL is,

Actually, an integer (or a pointer, which is the same).

JB> or what the format the
JB> parameter for NSSelectorFromString takes.

An NSString.

JB> @implementation AppMenuController
JB> - (void)awakeFromNib
JB> {
JB> //create menu
JB> SEL action = NSSelectorFromString(@"item1");
JB> appMenu=[[NSMenu alloc] initWithTitle:@"title"];
JB> [appMenu addItem:[ [NSMenuItem alloc] initWithTitle:@"item 1"
JB> action:action keyEquivalent:@""] ];
JB> }
JB> -(void) item1
JB> {
JB> NSLog(@"%@",@"\nItem1 selected");
JB> }

JB> When running the app "item 1" shows up and is selectable, but when I
JB> select it I get no log message. Can anyone help

Forgot to set the target. Incidentally, for cases like this there's the
@selector directive, which is much faster (being a compile-, or rather
link-time constant):

NSMenuItem *mi;
appMenu=[[NSMenu alloc] initWithTitle:@"title"];
[appMenu addItem:mi=[[NSMenuItem alloc] initWithTitle:@"item 1"
action:@selector(item1) keyEquivalent:@""]];
[mi setTarget:self];

You need the NSSelectorFromString only in case the name is generated somehow:

NSString *name=...read some config file, eg...
SEL action= NSSelectorFromString([name stringByAppendingString:@":"]);
...
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc


  • Follow-Ups:
    • Re: SEL and NSSelectorFromString
      • From: Jeff Galyan <email@hidden>
References: 
 >SEL and NSSelectorFromString (From: Jason Blake <email@hidden>)

  • Prev by Date: URLHandleUsingCache returns NSHTTPURLHandle
  • Next by Date: Re: message to nil? (very basic question)
  • Previous by thread: Re: SEL and NSSelectorFromString
  • Next by thread: Re: SEL and NSSelectorFromString
  • Index(es):
    • Date
    • Thread