Objective C: ResignFirstResponder with a button

我只是一个虾纸丫 提交于 2019-12-24 06:00:36

问题


Is there a way for a UIButton to trigger resignFirstResponder? I have my program set to do so in a function when you tap outside of a textfield, but I want the keyboard to go away when the user hits the submit button.

This is what I have for the UITextFields

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 [x1 resignFirstResponder];
 [x2 resignFirstResponder];
 [y1 resignFirstResponder];
 [y2 resignFirstResponder];
}

回答1:


Given the existence of the method you mention, how about:

- (IBAction)solve:(id)sender {
   [x1 resignFirstResponder];
   [x2 resignFirstResponder];
   [y1 resignFirstResponder];
   [y2 resignFirstResponder];
}


来源:https://stackoverflow.com/questions/4456204/objective-c-resignfirstresponder-with-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!