嗨,伙计们,我正在尝试在我的代码中添加一个 if 语句,以便当用户单击撤消按钮时,他们可以撤消它,但前提是数字为正,因此如果数字为零,则屏幕上会弹出一条消息说无法撤消计数。有点像 android 中的祝酒词,但无论在 ios 中是什么
//
// 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