Hi
I'm new to working with timers on the iPhone and would need some support.
I have a method as below that takes the time and update a label in my user interface. I also have an NSTimer that calls that method once a second (I only show hours and minutes). This works just fine, except for the first second the App is live (as I understand it takes one second before the timer calls the method).
I would like to call my method from viewDidLoad, but how can I supply the right arguments? Or is there a better way of doing this?
// Timer for updating time
[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];
// display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTimeString = [dateFormatter stringFromDate:currentTime];
[dateFormatter release];
timeLabel.text = currentTimeString;
}
Appreciate anything that would point me in the right direction.