Recently, I saw a demo on the Internet, "add a hidden toolbar to the keyboard in iPhone development". After running the demo, I found that after clicking "hide the keyboard, the previous TableView cannot be restored to the display when the application is started, because when TextField gets the focus, a soft keyboard will pop up, and the corresponding TableView on the Interface needs to be adjusted through the program, modifying its Frame will move above. (Note: Five textfields are included in TableView ). However, after you click "Hide keyboard", TableView remains unchanged after its Frame is modified, but it is not restored to the original appearance when the application was started.
Tried
-(Void) textFieldDidEndEditing :( UITextField *) textField; the method adds the statement that modifies the TableView Frame to restore the display when it is started, but it is found that as long as the focus of TextField changes, this API is called. For example, you can jump from the first TextField to the second TextField, switch the focus from the first to the second, and then switch from the second to the third and fourth... This API is called as long as any TextField loses focus. As a result, every time a focus switch occurs, the page will first restore the display when the application is started, and then quickly become the modified Frame.
You have also tried to register the keyboard display and implicit notifications.
The same is found. when the focus is switched from one TextField to another, the system sends the UIKeyboardWillHideNotification and UIKeyboardWillShowNotification notifications one after another. You still cannot achieve the desired effect, that is, after you click "Hide keyboard, restore the TableView display on the main interface.
Then I thought of a custom notification to solve this problem:
In the Demo, there is a HiddenKeyBoard function. This is the selector that will be called after you click the "Hide keyboard" button. Then, add the send notification statement in it:
[[Nsnotifcencenterdefacenter] postNotificationName: @ "mytest" object: nil];
Then, register the notification in ViewController's viewWillAppear:
-(Void) viewWillAppear :( BOOL) animated {
[[Nsnotificationcenterdefacenter] addObserver: selfselector: @ selector (doAfterKeyboardbarHidden :) name: @ "mytest" object: nil];
[Super viewWillAppear: animated];
}
-(Void) viewWillDisappear :( BOOL) animated {
// [[Nsicationicationcenter defacenter center] removeObserver: self];
[[Nsnotifcencenterdefacenter] removeObserver: selfname: @ "mytest" object: nil];
[Super viewWillDisappear: animated];
}
-(Void) doAfterKeyboardbarHidden :( NSNotification *) notification {
// Id obj = [notification object]; // get the passed object
NSLog (@ "++ // ++ ");
Tableview. frame = CGRectMake (320,340 );
}
OK! The desired effect is achieved!
Paste two pictures: the first one is input. After the input is complete, click "Hide keyboard". The interface will be displayed again immediately, that is, the second figure:
From Code Heaven