2011-07-07 50 views
0

使用XCode 3.2,我试图做的是有用户输入数据,然后他们有三个选择如何处理该数据,即有三个不同的选项或三个按钮,我想在相同的窗口。我想不出来有编码...如何在同一个窗口中使用多个按钮?

现在我有一个按钮被激活使用

-(IBAction)buttonPressed 
{ (formula) 
} 

我怎么做这个有多个按钮?

我找了答案,但他们有点不同,我在找什么。非常感谢!

回答

1

在创建按钮设置mybutton.tag = 0;像this.change 0至UR自己和buttonpressed功能比较它们

使用发件人

-(IBAction)buttonPressed:(id)sender 

    { 

     UIButton *temp=(UIButton*)sender; 


     if([temp tag] == 0) 
     (formula) 

     //button 0 

     } 

     if([temp tag] == 1) 
     (formula) 

     button 1 
    } 

    } 
0

按下按钮的代码应该是这样的:

- (IBAction)buttonPressed:(id)sender { 
    UIButton *senderButton = (UIButton *)sender; 
    if (senderButton == btnOK) { 
     // this is the OK button 
    } else if (senderButton == btnCancel) { 
     // this is the Cancel button 
    } 
} 

但是,一种更好的方法可能是编写三个单独的方法,并将每个方法挂钩到IB中相应的按钮。

相关问题