我得到了一個無符號整數的定時器。但是當它減去1時,它的值是零,它顯示一個正數。像這樣:http://prntscr.com/2wkydb。 這裏是我的代碼Viewcontroller.m:顯示一個int。我得到一個正數,當我減去1時,值爲0
-(IBAction)btnUp:(id)sender
{
timer = timer + 1;
lblTimer.text = [NSString stringWithFormat:@"%u", timer];
}
-(IBAction)btnDown:(id)sender
{
timer = timer - 1;
lblTimer.text = [NSString stringWithFormat:@"%u", timer];
}
-(IBAction)btnRestart:(id)sender
{
lblTimer.text = [NSString stringWithFormat:@"0"];
}
Viewcontroller.h:
@interface ViewController : UIViewController
{
unsigned int timer;
IBOutlet UILabel *lblTimer;
}
-(IBAction)btnUp:(id)sender;
-(IBAction)btnDown:(id)sender;
-(IBAction)btnRestart:(id)sender;
@end
什麼我需要做的,因此不顯示正數,但計時器停留在0? 在此先感謝。
編輯:我也不希望計時器顯示負值。
使用簽名者INT。 – Larme
我也不希望數字是負數。 – Bas
@Bas然後檢查它是否爲零,然後從中減去1。 –