《30天精通iPhone手机编程》-Day11-点数器

这一章就是设计了一个计数器,涉及整数数据转换成文字格式数据的方法。

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];	
	count = 0;
	//用于取得文字数据类型,把整数数据转换为文字格式数据
	NSString *numValue = [NSString stringWithFormat:@"%d", count];	
    //数字显示标签的文字替换为字符变量numValue中的数据内容
	counter.text = numValue;	
}
- (IBAction)addUnit {	
	if(count <= 999){ 
		count++;
	}else {
		count=999;
	}
    //创建一个字符变量numValue,用于取得文字数据类型,把整数数据转换为文字格式数据
	NSString *numValue = [NSString stringWithFormat:@"%d", count];
	//数字显示标签的文字替换为字符变量numValue中的数据内容
	counter.text = numValue;	
}
//减法
- (IBAction)subtractUnit {	
	if(count >0){ 
	    count--;
	}else {		
		count=0;		
	}
	NSString *numValue = [NSString stringWithFormat:@"%d", count];
	counter.text = numValue;	
}
//重置
-(IBAction)reset{	
	count = 0;
	NSString *numValue = [NSString stringWithFormat:@"%d", count];
	counter.text = numValue;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值