> Greetings, > > I am having trouble with something that should be pretty > basic.. > > What I would like to do is set the action for NSButton > programmatically where the selector is a variable. > > I can't seem to find an example. > > [aButton addTarget:self action:variable ....] > > If I define 'variable' to be NSString it is happy > but at run time I > get an error stating that the target selector is Null. I > can assure > you that variable exists and has a value of > 'buttonAction:'. > > I of course have buttonAction defined as follows: > > - (void) buttonActon:(id)sender > > > What am I doing wrong? > > -mark=
Hi Mark, The "action" needs to be a SEL type (a selector). There is a function in Foundation: NSSelectorFromString (NSString *aSelectorName), which returns selector for <aSelectorName> if one exists. You can pass this to a -setAction: method of NSControl (of which NSButton is a subclass). NSSelectorFromString documentation: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSelectorFromString -setAction: documentation: http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSControl_Class/Reference/Reference.html#//apple_ref/occ/instm/NSControl/setAction: (Note that the colon in above URL is a part of URL) HTH Gorazd __________________________________________________________________ Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com _______________________________________________ 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]