夢見るポテト

色々きになったことを書いてこうと思う

iCounter(カウンター)(ほぼ)完成

素材は自分で作れないのでiPhone SDKの教科書のサイトから
使わさせていただきました。
f:id:heart02:20120804124707j:plain

これで完成したんですが、
ふと思って今の状態で9999回カウント以上するとどうなるんだろうと
思い9999回カウントした状態にしたら桁が増えてとんでもないことになったので
ソースコードを直しました。
(9999回ボタンを押すのが面倒だったので9999カウントを足しました)
f:id:heart02:20120804125326p:plain


ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{

IBOutlet UILabel *display;
    int count;
    
}
-(IBAction)add;
-(IBAction)subtract;
-(IBAction)clear;

@end


ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(void)updataDisplay
{
    display.text =[NSString stringWithFormat:@"%04d",count];
    
}


-(IBAction)add{             //+カウントする
    count = count + 1;
    if(count >= 9999)
        count = 9999;
    [self updataDisplay];
   // display.text = [NSString stringWithFormat:@"%d",count];
    
}

-(IBAction)subtract{
    count = count - 1;
    if(count < 0)
            count =0;
    [self updataDisplay];
    //display.text = [NSString stringWithFormat:@"%d",count];
}

-(IBAction)clear{
    
    count = 0;
    [self updataDisplay];
    //display.text = [NSString stringWithFormat:@"%d",count];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end