2011-11-05 76 views
2

我在簡單的回調中遇到了一些麻煩;即使我找不到任何錯誤,我也會得到'期望的方法體'錯誤。已評論錯誤消息。回調錯誤(預期的方法體)

Logger.h

#import <Foundation/Foundation.h> 

@interface Logger : NSObject 

- (void)sayOuch:NSTimer *)t; // Expected ';' after method prototype 

@end 

Logger.m

#import "Logger.h" 

@implementation Logger 

- (void)sayOuch:NSTimer *)t // expected method body 
{ 
    NSLog(@"Ouch!"); 
} 

@end 

的main.m

#import <Foundation/Foundation.h> 
#import "Logger.h" 

int main (int argc, const char * argv[]) 
{ 

    @autoreleasepool { 

     Logger *logger = [[Logger alloc]init]; 

     NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 
                 target:logger 
                selector:@selector(sayOuch:) 
                userInfo:nil 
                repeats:YES]; 

     [[NSRunLoop currentRunLoop]run]; 

    } 
    return 0; 
} 

回答

7

你有

- (void)sayOuch:NSTimer *)t; 

但是你應該有

- (void)sayOuch:(NSTimer *)t; 

你錯過了開括號爲NSTimer *

+0

哎喲!是的,這解決了它。謝謝。 – pdenlinger