我創建了一個自定義的類,它顯示時間日期格式,我需要像法的定時器來更新秒,所以這裏是我的代碼:更新NSDateFormatter用的NSTimer
CustomClass.m
- (NSString *) showLocaleTime {
NSDateFormatter *timeFormater = [[NSDateFormatter alloc] init];
timeFormater = [setDateFormat:@"HH:mm:ss "];
NSString *currDay = [timeFormater stringFromDate:[NSDate date]];
currDay = [NSString stringWithFormat:@"%@",currDay];
[timeFormater release];
return timer;
}
- (void) updateLocaleTime {
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showLocaleTime) userInfo:nil repeats:YES];
}
viewController.m:
CustomClass *time = [[CustomClass alloc]init];
label.text = [time showLocaleTime];
[time updateLocaleTime];
但問題是updateLocaleTime
不叫更新秒!我錯過了什麼嗎? 謝謝
有沒有辦法像我說的那樣調用這個方法? :-s我需要它,它的公共API給我的朋友我需要它非常簡單 – 2012-01-12 13:03:28
正如愛因斯坦所說,一切都應該儘可能簡單,但並不簡單。 – 2012-01-12 13:29:15
謝謝,但我收到了'SIGABRT' !!? – 2012-01-12 13:52:54