Here’s my code (it’s wrapped in an IBAction that is called when the button is pressed):
if (myButton.currentTitle == @"test") {
[myButton setTitle:@"test2" forState:UIControlStateNormal];
}
if (myButton.currentTitle == @"test2") {
[myButton setTitle:@"test" forState:UIControlStateNormal];
}
I want the UIButton text to toggle when pressed (if text = “test” then change to “test2” and when pressed if text = “test2” change to “test”).
I do have an IBOutlet connected for myButton and the the IBAction connected to myButton–so I am pretty sure it isn’t a problem with my connections.
For some reason this isn’t working, I’m sure I am missing something very simple.
use isEqualToString: instead of ==