I have a UIButton in the Interface Builder with the initial title "Use Current Location". There is a UITextField above where the user can type in an address or a zipcode. Both the button and the text field are IBOutlets.
The view controller for the view in which these items exist is a UITextFieldDelegate. In the delegate method (BOOL)textFieldShouldReturn:(UITextField *)textField I want to change the button title depending on whether the text field has anything in it or not. My method looks like this:
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSLog([textField text]);
if([[textField text] length] == 0)
{
NSLog(@"AAAAAAAAA");
[go setTitle:@"Use Current Location" forState:UIControlStateNormal];
}
else
{
NSLog(@"BBBBBBB");
[go setTitle:@"Use This Address" forState:UIControlStateNormal];
}
[textField resignFirstResponder];
return YES;
}
Note: go is the UIButton.
This method isn't preforming as expected, but it logs the correct statements each time. The button's title just doesn't change.
Any help would be particularly appreciated.
Check the connections in the Interface Builder, make sure the button is connected to its outlet and that the delegate for the textfield is set up correctly.
Is your "go" button connected properly? Print the go buttons address and check if it is non-null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With