'updateTimer' undeclared (first use in this function)
I get this error ''updateTimer' undeclared (first use in this function)'
This is the code:
#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:(u开发者_开发百科pdateTimer) userInfo:nil repeats:YES];
[super viewDidLoad];
}
The error is on the viewdidload line of 'timer'
It should be @selector(updateTimer)
instead of (updateTimer)
.
- (void)viewDidLoad
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
[super viewDidLoad];
}
精彩评论