0

嗨,伙计们,我正在尝试在我的代码中添加一个 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
4

1 回答 1

0

要将 Toast 放在 android 中,请访问https://www.cocoacontrols.com/controls/itoast并下载库。这将是显示 toast 的代码。将 iToast.h 和 .m 文件拖到您的包中。

viewController.m

#import "iToast.h"

在方法中这样做

   if(/*your condition here*/)
    {
        iToast * toast = [iToast makeText:@"Toast"];
        [toast setDuration:iToastDurationNormal];
        [toast show:iToastTypeInfo];

}

于 2013-07-02T11:38:03.010 回答