Objective C - one button with multiple sequential outcomes
I am new to programing so any help is appreciated. I am trying to find the method for the following. I need one button that will, when executed, perform a different task in a sequence when activated. For exam开发者_高级运维ple the first time that the button is pressed, I would like it to act as if the user is confirming the information in the title of the button (i.e. confirms that the user is older than 45). The second time that the user presses the button it confirms the response in the negative (i.e. confirms the user is NOT older than 45). The third time the user presses the button the field is reset and no value has been assigned (i.e. it is as if the user never answered the question).
For real-estate purposes I would like the information in question to be the title of the button and update appropriately once the action has been captured. For example, if the action is positive the display is shown with a circle around the title. If the action results in a negative response, the title is shown with a line through it.
I have done quite a bit or reading to try to get a solution but no dice so far. I have tried overlaying a button on a label with the text of the label changing, but so far I am not having any luck
I can't imaging that this is a unique issue and any help is appreciated. Much thanks in advance.
On the event just have some code like this
Header
- (IBAction)buttonPressed:(id)sender{
static int counter;
if (counter == 0){
// do stuff for first time Example [sender setTitle:@"45"];
}else if (counter == 1){
// do stuff for second time Example [sender setTitle:@"-45"];
}else if (counter == 2){
// do stuff for the third time
}
counter += 1;
if (counter > 2){
// restart the counter
counter = 0;
}
}
精彩评论