Re: question about selector as argument
Re: question about selector as argument
- Subject: Re: question about selector as argument
- From: Andy Lee <email@hidden>
- Date: Sat, 18 Jun 2005 11:13:19 -0400
On Jun 18, 2005, at 9:34 AM, Ivan S. Kourtev wrote:
@implementation foo // a foo object is to be called back
...
- (void)callbackFunction:(int)x { /* define the callback */ }
...
// inside some other method
boo* b;
...
[b doSomething:self withCallBack:@selector( callbackFunction: )]
...
...
#end
@implementation boo
...
- (void)doSomething:(id)anObject withCallBack:(SEL)aSelector {
...
[anObject aSelector:10];
This line of code only works if anObject has a method called
"aSelector:". You don't want to send a message *called* "aSelector:"
to anObject, you want to send the message indicated by the value of
the aSelector variable.
You were on the right track with -performSelector:withObject:. Try
this:
[anObject
performSelector:aSelector
withObject:[NSNumber numberWithInt:10]];
Note: this requires that -callbackFunction: take an NSNumber argument
rather than an int.
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden