0
我已閱讀了關於如何在iOS中創建時鐘的指南。而且,它的工作原理應該和所有這一切,但我想進一步,並獲得時鐘來更新每個minut。所以它不再是「靜態的」,所以如果你在上午12點16分打開應用程序,並讓它運行,它應該自動更新每個分鐘(上午12:17,上午12:18等)。獲取時間在iOS中「運行」
這是指導與提供我的代碼,
NSDateFormatter *datoVar = [[NSDateFormatter alloc] init];
[datoVar setDateFormat:@"hh:mm"];
LabelKlokken.text = [datoVar stringFromDate:[NSDate date]];
我試過,並試圖通過谷歌和計算器看,但就是無法找到任何東西。
在此先感謝,Oluf尼爾森。
EDITED:我的代碼現在看起來像這樣
-(void)clock
{
NSDateFormatter *datoVar = [[NSDateFormatter alloc] init];
[datoVar setDateFormat:@"hh:mm"];
LabelKlokken.text = [datoVar stringFromDate:[NSDate date]];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self clock];
tid = nil;
tid = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(clock) userInfo:NULL repeats:YES];
}
嘿,感謝:-),但它不到風度的工作,它不給我一個錯誤下去,但仍然無法更新,請檢查我的編輯:)! – 2011-04-19 10:33:09
Nvm。它的工作原理,現在:)我非常感謝你! – 2011-04-19 10:36:09
沒問題,閱讀編輯,這很重要:) – 2011-04-19 10:42:48