ここに問題がありNSString
ます。ビューがロードされたときに int 値を持つ 3 つの s があり、これを実行する必要があります。
NSCalendar* gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int uintFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents* differenceComponents = [gregorian components:uintFlags
fromDate:quitDate toDate:nowDate options:0];
NSString *hours1 = [NSString stringWithFormat:@"%d",[differenceComponents hour]];
hours = hours1;
NSString *minutes1 = [NSString stringWithFormat:@"%d",[differenceComponents minute]];
minutes = minutes1;
NSString *seconds1 = [NSString stringWithFormat:@"%d",[differenceComponents second]];
seconds = seconds1;
それらNSString
には int 値が含まれるようになったので、int を static に設定することはできませんか? こういうのやりたかったからやめた…
- (void)updater:(id)sender {
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self
selector:@selector(timer:) userInfo:nil repeats:YES];
}
- (void)timer:(id)sender {
// I get error right here that says (initialize
// element is not a compile-contstant)
static int hour = hours.intValue;
static int minute = minutes.intValue;
static int second = seconds.intValue;
NSString *sec = [NSString stringWithFormat:@"%i",second];
if (seconds1 < 10) {
sec = [NSString stringWithFormat:@"0%i",second];
}
NSString *min = [NSString stringWithFormat:@"%i",minute];
if (minutes1 < 10) {
min = [NSString stringWithFormat:@"0%i",minute];
}
NSString *hours5 = [NSString stringWithFormat:@"%i",hour];
NSString *timerTime = [NSString stringWithFormat:@"%@:%@:%@" ,hours5 ,min ,sec];
label1.text = timerTime;
seconds1 ++;
if (seconds1 > 59) {
seconds1 = 00;
minutes1 ++;
}
if (minutes1 > 59) {
minutes1 = 00;
hours1 ++;
}
}