(IBAction)按钮以标记输出 [英] (IBAction)button to label output

查看:54
本文介绍了(IBAction)按钮以标记输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iphone SDK对象C编程中的新功能..我想问的问题是,我如何运行带有2个按钮(递增1和递减2)的程序,以在标签中显示结果.每次单击"increment1"或"decrement1"时结果都会改变.对不起,我在对象c编程方面非常陌生,希望您能为我提供帮助:)谢谢

hi im new in iphone SDK object C programming.. this question i want to ask is that , how can i run a program with 2 buttons (increment 1 and decrement 2) to be shown the result in a label. with the result is changing everytime i click increment1 or decrement1. sorry im very new in object c progamming, hoping u can help me :) thank you

-标记

推荐答案

一旦您对Objective C和Xcode有点熟悉,就很容易实现.但是我的建议是对这些有所了解,以便其他开发人员也可以轻松地帮助您进行解释.

It is very easy to implement once you get a bit familiar with Objective C and Xcode. But my advice is get a bit familiar with these so that it would be also easy for fellow developers to help you explain.

我希望您已经创建了一个试用项目.会有.h .m和.xib文件.

I hope you have created a trial project to kick-start with. It would be having .h .m and .xib files.

  1. 在xib文件中包含两个UIButton和一个UILabel.

  1. Take two UIButtons and one UILabel in you xib file.

将Buttons和lable的插座连接到您的nib文件.

Connect the Buttons and lable's outlet to your nib file.

在.h和.m文件中添加以下代码.

Add the following code in your .h and .m files.

.h文件的代码

@interface RootViewController :     UIViewController<> {
IBOutlet UIButton *incrBtn;
IBOutlet UIButton *decrBtn;
IBOutlet UILabel *label;
NSInteger counter;

}

-(IBAction)incr;
-(IBAction)decr; 

.m文件的代码

- (void)viewDidLoad {
[super viewDidLoad];
counter=0;
label.text=[NSString stringWithFormat:@"%d",counter];
}

-(IBAction)incr{
counter++;
label.text=[NSString stringWithFormat:@"%d",counter];


}

-(IBAction)decr{
counter--;
label.text=[NSString stringWithFormat:@"%d",counter];


}

就是这样!

这篇关于(IBAction)按钮以标记输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆