2013-07-02 47 views
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 
+0

哪裏是if語句在這? – Durgaprasad

+0

即時通訊還沒有完成,但我知道如何做到這一點的android,但還沒有得到一個線索如何做到這一點蘋果 – Charlotte

+0

如果(數字== 0){} – Durgaprasad

回答

0

了一下,把麪包作爲android系統中去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]; 

}

+0

這是你想要的嗎? – Durgaprasad