开发者

UITextField to resign first responder on UIButton touch

开发者 https://www.devze.com 2023-03-26 03:21 出处:网络
I have a UITableView with some cells containing UITextField objects and others with UIButton objects. When one of t开发者_运维技巧he textFields is first responder (keyboard showing) i am having troubl

I have a UITableView with some cells containing UITextField objects and others with UIButton objects. When one of t开发者_运维技巧he textFields is first responder (keyboard showing) i am having trouble resigning its first responder status. When a user clicks or touches a button in another cell, the textField is still not resigning even though i am calling [textField resignFirstResponder] on the 'did end on exit' and 'Editing did end' events. I am also calling [button becomeFirstResponder] when the button is clicked. I guess it has to do with objects being in different cells. any ideas?

EDIT:

i am resigning the first responder like this:

-(IBAction)endEditing:(id)sender {

    UITextField *textField = (UITextField *)sender;
    [textField resignFirstResponder];
}

the endEditing: method is called on both UITextField events: 'did end on exit' and 'Editing did end'.


Where are you calling this [textField resignFirstResponder] and where is this textField declared?

Proper way would be to declare an instance variable:

UITextField *activeTextField;

And once any text field becomes active set it as activeTextField. Then when you press the button do [activeTextField resignFirstResponder]; activeTextField = nil;

0

精彩评论

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