0
嗨,大家好我想添加一個if語句到我的代碼,以便當用戶點擊撤消按鈕時,他們可以撤消它,但只有當數字如果是正數,所以如果數字是零,那麼屏幕上會彈出一條消息說無法撤消計數。像在Android上烤麪包,但不管它是在iOS創建一個依賴於整數的if語句
//
// ViewController.m
// counter
//
// Created by Charlotte on 23/06/2013.
// Copyright (c) 2013 Charlotte. All rights reserved.
//
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
-(IBAction)Up:(id)sender{
Number=Number+1;
Count.text = [NSString stringWithFormat:@"%i", Number];
[[NSUserDefaults standardUserDefaults] setInteger:Number forKey:@"savenumber"];
}
-(IBAction)Down:(id)sender{
Number=Number-1;
Count.text = [NSString stringWithFormat:@"%i", Number];
[[NSUserDefaults standardUserDefaults] setInteger:Number forKey:@"savenumber"];
}
-(IBAction)Restart:(id)sender{
Number=0;
Count.text = [NSString stringWithFormat:@"%i", Number];
[[NSUserDefaults standardUserDefaults] setInteger:Number forKey:@"savenumber"];
}
- (void)viewDidLoad
{
Number = [[NSUserDefaults standardUserDefaults] integerForKey:@"savenumber"];
Count.Text = [NSString stringWithFormat:@"%i",Number];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
哪裏是if語句在這? – Durgaprasad
即時通訊還沒有完成,但我知道如何做到這一點的android,但還沒有得到一個線索如何做到這一點蘋果 – Charlotte
如果(數字== 0){} – Durgaprasad