开发者

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:(UITextF开发者_如何学运维ield *)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.


Definitely has something to do with the button not being linked appropriately. It is, however, obvious that you already have your UITextField's delegate working as you're logging the correct log statement.

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜