2011-01-21 106 views
0

嗨即时通讯新的iphone SDK对象C编程..这个问题我想问的是,我怎么能运行一个程序与2个按钮(增量1和递减2)被显示产生一个标签。结果每次我都点击增量1或递减1。 对不起IM在对象C预设电台很新,希望u能帮助我:) 谢谢(IBAction)按钮标签输出

-mark

+2

你需要检查网络上一些初步的教程,然后如果你有任何问题,那么你可以问here.But首先你应该尝试至少。 – Ishu 2011-01-21 06:10:17

回答

0

注:这些是基本的东西,你可以通过google搜索本身得到。检查这link

提示您的方案:

- 创建2个按钮的视图,1个标签

- 设置的标签IBOutlet中

每个按钮 - 设置标签

-assign同样的动作[说 - (IBAction)buttonAction:(id)发件人]两个按钮,

- 有一个gl 10:28整varible(比如VAL)

-Code如下

-(IBAction)buttonAction: (id)sender 
{ 
UIButton *but=(UIButton *)sender; 
if(but.tag==1) 
{ 
    val++; 
    [label setText:[NSString stringWithFormat:"%@"],val]; 
} 
else 
{ 
    val--; 
    [label setText:[NSString stringWithFormat:"%@"],val]; 
} 
} 
1

这是很容易实现的,一旦你变得有点熟悉目标C和Xcode.I将会帮助你在这个one.But我的建议是有点熟悉这些,以便开发人员也可以很容易地帮助你解释..

我希望你已经创建了一个试用项目,开始使用。它会有.h .m和.xib文件。

  1. 在你的xib文件中带两个UIButton和一个UILabel。

  2. 将按钮和标签的插座连接到您的笔尖文件。

  3. 将下面的代码添加到.h和.m文件中。

代码.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]; 


} 

和多数民众赞成它!您准备去mate..So继续和代码!!所有BEST

干杯