How to use multiple buttons in the same window?
Using XCode 3.2, What I'm trying to do is have the user input data and then they have three choices of what to do with that data, i.e. there are three different options or three buttons that I want to have in the same window. I can't figure out to have that coded...
right now i have one button that is activated using the
-(IBAction)buttonPressed
{ (formula)
}
how do I do this with multiple buttons?
I've looked for answers but they are a bit different than 开发者_Python百科what Im looking for. Thank you so much!
while creating buttons set mybutton.tag=0;like this.change 0 to ur own and compare them in buttonpressed function
use sender to
-(IBAction)buttonPressed:(id)sender
{
UIButton *temp=(UIButton*)sender;
if([temp tag] == 0)
(formula)
//button 0
}
if([temp tag] == 1)
(formula)
button 1
}
}
Button press code should look like this:
- (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
}
}
A better way, though, is probably to write three separate methods, and hook each one up to its corresponding button in IB.
精彩评论