开发者

UIButton not disabled when UITextField has focus

开发者 https://www.devze.com 2023-01-01 16:30 出处:网络
I have a UIButton - a submit button - that I set the enabled and disabled states and titles for. I use the submit button title to show status like @\"Sending...\" while my program is making an api cal

I have a UIButton - a submit button - that I set the enabled and disabled states and titles for. I use the submit button title to show status like @"Sending..." while my program is making an api call by disabling the button.

It works fine until the edge case where someone enters a comment on a UITextField, 开发者_运维知识库but instead of dismissing the keyboard/finishing editing just hits the SUbmit button (so the keyboard is still up). In this case, disabling the button doesn't change the title and background to the disabled state.

Is this an issue with firstResponder? I'm trying to explicity tell the comment field to resignFirstResponder before setting the button.enabled = NO, but it still doesn't update the button.


Are you implementing this UITextFieldDelegate method:

- (void)textFieldShouldEndEditing:(UITextField *)textField {
    [textField resignFirstResponder];
    button.enabled = NO;
}

and then resigning the text field's first responder and disabling the button?


Sometimes textFieldSHouldEndEditing doesn't get called since the field may not lose focus, so I do try to explicity tell the text field to resign before disabling the button. Doesn't seem to work...

0

精彩评论

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