创建依赖于整数的if语句

时间:2013-07-02 11:19:17

标签: ios if-statement count

大家好我正在尝试在我的代码中添加一个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

1 个答案:

答案 0 :(得分:0)

要像在Android中一样放入Toast,请转到https://www.cocoacontrols.com/controls/itoast并下载库。 这将是展示吐司的代码。将iToast.h和.m文件拖到捆绑包中。

viewController.m

#import "iToast.h"

在方法中执行此操作

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

}