1, click the other blank areas of the interface to hide
Since Uiviewcontroller is inherited from Uiresponder, it is possible to overwrite-(void) Touchesbegan: (nsset *) touches withevent: (uievent *) event; This starts the touch method to cancel the first responder, The code is as follows:
[CPP]View Plaincopy
- When you click outside the edit box, hide the keyboard
- -(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
- {
- [[Self.viewviewWithTag:TAG_WORD] resignfirstresponder];
- [[Self.viewviewWithTag:TAG_PROVINCE] resignfirstresponder];
- }
2. When you click Return or done on the keyboard, hide the keyboardThis method is Uitextfield implemented delegate, when the return button on the keyboard is clicked, the -(BOOL) Textfieldshouldreturn in delegate is called: ( Uitextfield *) TextField method.
Code:
[CPP]View Plaincopy
- Hide the keyboard when you click Return or done on the keyboard
- -(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
- {
- [TextField Resignfirstresponder];
- }
iOS Learning: Hiding keyboard methods