2010-10-12 28 views
1

是否可以從選擇器調用對象的實例方法?以下可能嗎?它給了我編譯錯誤,「:」丟失或什麼:從目標C選擇器調用實例方法

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

回答

2

更改目標self.person並使用舞蹈選擇:

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

謝謝!那就是訣竅!我會在7分鐘內接受你的答案:) – azamsharp 2010-10-12 16:52:11

+0

只需詳細說明,選擇器不是一個方法調用本身,而是發送給對象的消息告訴該對象使用什麼方法。在Objective-C中,你從不直接調用方法。因此,該選擇器僅用完整方法名稱識別該方法,例如, 'DoSomething的:戕:andB' – TechZen 2010-10-12 17:13:07

0

你試過改變目標?就像這樣:

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