Как я могу изменить этот код, чтобы он имел ЧЧ: ММ: СС (часы, минуты, секунды,
И вы можете сказать мне, нужно ли мне добавить код в .h или .m, чтобы я знал, какой из них
в данный момент увеличивается как 1, 2 , 3, 4 и т. Д.
привет, ребята, просто чтобы вы знали, что я наживка любителя, не могли бы вы скопировать и пропустить, чтобы я знал, что вы имеете в виду, спасибо
С уважением
Пол
.h
@interface FirstViewController : UIViewController {
IBOutlet UILabel *time;
NSTimer *myticker;
//declare baseDate
NSDate* baseDate;
}
-(IBAction)stop;
-(IBAction)reset;
@end
.m
#import "FirstViewController.h"
@implementation FirstViewController
-(IBAction)start {
[myticker invalidate];
baseDate = [NSDate date];
myticker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
}
-(IBAction)stop;{
[myticker invalidate];
myticker = nil;
}
-(IBAction)reset;{
time.text = @"00:00:00";
}
-(void)showActivity {
NSTimeInterval interval = [baseDate timeIntervalSinceNow];
NSUInteger seconds = ABS((int)interval);
NSUInteger minutes = seconds/60;
NSUInteger hours = minutes/60;
time.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes%60, seconds%60];
}