2013-09-10 43 views
-2

在我使用Xcode的課程中,我們正在爲我們的遊戲應用添加一個計時器。編寫方法有困難(新手)

沒有爲這個課程和我自己編寫的書,我的所有其他同學都在使用目標c編寫代碼。這應該是Xcode和應用程序開發的入門課程,但我們無法使用這種語言。

我們需要填寫這三種方法:

//Clock.m file 

#import "Clock.h" 

@implementation Clock 

int seconds = 1; 
int minutes = 60; 

- (NSString*) currentTime { 
    //return the value of the clock as an NSString in the format of mm:ss 
} 
- (void) incrementTime { 
    //increment the time by one second 
} 
- (int) totalSeconds; 
    //return total seconds in the value of an (int). 
@end 

有沒有人有任何教程鏈接或可以幫助填補這些空白和深入淺出的講解它們的代碼的語法?

+0

This SO answer about NSTimer is quite good。 http://stackoverflow.com/a/1449104/592739 –

+1

放下你正在工作的任何東西並開始閱讀[*今天開始開發iOS應用程序*](https://developer.apple.com/library/ios/ referencelibrary/gettingstarted /使用RoadMapiOS /章節/ Introduction.html#// apple_ref/DOC/UID/TP40011343)。它鏈接到許多其他資源,並將整體節省您的痛苦和沮喪。 –

回答

2

你應該首先問Google。把你的問題分成小塊,然後從那裏出發。

希望這有助於你一邊學習!

#import "Clock.h" 

@implementation Clock 

int _time = 0; 

- (NSString*) currentTime { 
    //return the value of the clock as an NSString in the format of mm:ss 
    //You will get minutes with 
    int minutes = _time/60; 
    //remaining seconds with 
    int seconds = _time % 60; 

    NSString * currentTimeString = [NSString stringWithFormat:@"%d:%d", minutes, seconds]; 

    return currentTimeString; 
} 
- (void) incrementTime { 
    //increment the time by one second 
    _time++; 
} 
- (int) totalSeconds { 
//return total seconds in the value of an (int). 
    return _time; 
} 
@end 
+0

謝謝!這是有幫助的,閱讀它是有道理的。最初我對谷歌感到沮喪,但也許我只是不知道如何正確地提出問題以獲得我需要的解釋。一旦我的下一堂課結束,我會嘗試這個代碼,我會檢查這是否有效。 –