I am new to working with timers on iPhoneand need some support.
I have a method as shown below that takes time and updates UILabelin mine userinterface. I also have NSTimerone that calls this method once per second (I only show hours and minutes). This works fine except for the first second when the application is in real time (since I understand that it takes one second before timercalling the method).
I would like to name my method from viewDidLoad, but how can I provide the correct arguments? Or is there a better way to do this?
[NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(updateTime:)
userInfo:nil
repeats:YES];
-(void)updateTime: (NSTimer *) timer {
currentTime = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTimeString = [dateFormatter stringFromDate:currentTime];
[dateFormatter release];
timeLabel.text = currentTimeString;
}
Appreciate anything that points me in the right direction.