回调错误(预期的方法体)

时间:2011-11-05 00:04:21

标签: objective-c

在简单的回调中遇到了一些麻烦;我正在寻找一个预期的方法体'即使我找不到任何错误,也会出错。已评论错误消息。

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;
}

1 个答案:

答案 0 :(得分:7)

你有

- (void)sayOuch:NSTimer *)t;

但你应该

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

您错过了NSTimer *

的左括号