Using @selector()
Using @selector()
- Subject: Using @selector()
- From: "Christian Giordano" <email@hidden>
- Date: Sat, 9 Aug 2008 09:34:29 +0100
Hi guys, I'm a newbie and I'm reading a book which shows the two
different option to link programmatically a control to an action:
SEL mySelector;
mySelector = @selector(methodName:);
[myButton setAction:mySelector];
OR
SEL mySelector;
mySelector = NSSelectorFromString(@"methodName:");
[myButton setTarget:someObjectWithTheMethod];
[myButton setAction:mySelector];
On my test, the first syntax doesn't seem to work. This is my implementation.
- (void)awakeFromNib
{
NSLog(@"awakeFromNib");
SEL mySelector;
mySelector = @selector(sayIt:);
[sayItButton setAction:mySelector];
}
If I do the other syntax:
- (void)awakeFromNib
{
NSLog(@"awakeFromNib");
SEL mySelector;
mySelector = NSSelectorFromString(@"sayIt:");
[sayItButton setTarget:self];
[sayItButton setAction:mySelector];
}
Works. The sayIt method is in the same class than the awakeFromNib of
course. Any ideas?
Thanks, chr
_______________________________________________
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