'updateTimer'未声明(首次使用此功能)

时间:2011-10-02 23:38:51

标签: objective-c cocoa-touch

我收到此错误''updateTimer'未声明(首次在此函数中使用)'

这是代码:

#import <UIKit/UIKit.h>


@interface SleepAppFinalViewController : UIViewController
{

    //IBOutlet UILabel *myLabel;

    IBOutlet UILabel *_label;
    NSTimer *timer;

}

-(void)updateTimer;

的.m

@implementation SleepAppFinalViewController

-(void)updateTimer {

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"hh:mm:ss"];
    _label.text = [formatter stringFromDate:[NSDate date]];
    [formatter release];
}

- (void)viewDidLoad
{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:(updateTimer) userInfo:nil repeats:YES];
    [super viewDidLoad];


}

错误发生在'timer'

的viewdidload行上

2 个答案:

答案 0 :(得分:5)

应该是@selector(updateTimer)而不是(updateTimer)

答案 1 :(得分:1)

- (void)viewDidLoad
{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
    [super viewDidLoad];


}