• 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: question about selector as argument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >question about selector as argument (From: "Ivan S. Kourtev" <email@hidden>)

  • Prev by Date: Re: How to find an over-released object?
  • Next by Date: Re: question about selector as argument
  • Previous by thread: question about selector as argument
  • Next by thread: Re: question about selector as argument
  • Index(es):
    • Date
    • Thread