Re: Using @selector()
Am Sa,09.08.2008 um 11:23 schrieb Christian Giordano: yep, it works with that :) I presume it is an error in the book. Personally I thought that passing the method not as string it would have recognized the scope (target) automatically. Fortunaly they don't. Selector-dispatching is performed dynamically as every other message-dispatch. So the same selector can be executed on different objects of different classes. Otherwise some techniques of Cocoa wouldn't work (I. e. responder chain, bindings) Amin Thanks a lot, chr On Sat, Aug 9, 2008 at 9:45 AM, Jean-Daniel Dupas [EMAIL PROTECTED] wrote: Le 9 août 08 à 10:34, Christian Giordano a écrit : 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? Why you do not set the target in the first method ? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/negm-awad%40cocoading.de This email sent to [EMAIL PROTECTED] Amin Negm-Awad [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Using @selector()
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Using @selector()
Le 9 août 08 à 10:34, Christian Giordano a écrit : 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? Why you do not set the target in the first method ? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Using @selector()
yep, it works with that :) I presume it is an error in the book. Personally I thought that passing the method not as string it would have recognized the scope (target) automatically. Thanks a lot, chr On Sat, Aug 9, 2008 at 9:45 AM, Jean-Daniel Dupas [EMAIL PROTECTED] wrote: Le 9 août 08 à 10:34, Christian Giordano a écrit : 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? Why you do not set the target in the first method ? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Using @selector()
On 09.08.2008, at 11:23, Christian Giordano wrote: yep, it works with that :) I presume it is an error in the book. Probably. Or they hooked up the target in IB before that. Personally I thought that passing the method not as string it would have recognized the scope (target) automatically. Now you know better. FWIW, it helps me to think that @selector() is like referencing a function pointer directly, while NSSelectorFromString() is like using CFBundle or dyld of CFM's FindSymbol(), or whatever API you've used before to look up functions at runtime. If you've used one at runtime ... which I guess only compiler and plug-in nuts like me do, so forget what I said ... :-) Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://www.zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]