When I click on Start the stopWatchLabel
shows the following (its static, nothings runs):
- NOTE: When I test this app on my iPhone all runs as expected. No problems at all.
Can someone explain why?
.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
NSTimer *stopWatchTimer;
NSDate *startDate;
}
@property (strong, nonatomic) IBOutlet UILabel *stopWatchLabel;
- (IBAction)startButtonTapped:(id)sender;
- (IBAction)stopButtonTapped:(id)sender;
-(void)updateTimer;
@end
.m
- (IBAction)startButtonTapped:(id)sender {
stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
}
- (void)updateTimer
{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[dateFormatter stringFromDate:timerDate];
stopWatchLabel.text = timeString;
}
- (IBAction)stopButtonTapped:(id)sender {
[stopWatchTimer invalidate];
}