Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton not changing title

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.

like image 660
Mason Avatar asked Feb 07 '26 00:02

Mason


2 Answers

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.

like image 199
PengOne Avatar answered Feb 09 '26 08:02

PengOne


Is your "go" button connected properly? Print the go buttons address and check if it is non-null.

like image 21
Mugunth Avatar answered Feb 09 '26 07:02

Mugunth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!