views:

23

answers:

2

Is it possible to call the instance method of an object from the selector? Is the below possible? It gives me compilation error that ":" is missing or something:

timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                         target:self
                                       selector:@selector(([self.person dance]))
                                       userInfo:nil
                                        repeats:YES];   
A: 

Have you tried changing the target? Like this:

timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                         target:self.person
                                       selector:@selector(dance)
                                       userInfo:nil
                                        repeats:YES];   
fluchtpunkt
+1  A: 

Change target to self.person and use the dance selector:

timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self.person
                                   selector:@selector(dance)
                                   userInfo:nil
                                    repeats:YES];
Ben
Thanks! that did the trick! I will accept your answer in 7 min :)
azamsharp
Just to elaborate, a selector is not a method call itself but rather the message sent to object to tell that object what method to use. In Objective-C you never call methods directly. As such the selector merely identifies the method with the full method name e.g. `doSomething:withA:andB`
TechZen