问题
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