Reputation: 133
I've already checked other similar questions but none of them solved my problem. I have a window-based application and I'm using more windows in the same .xib file. In the first window, I have some text fields and I can hide the keyboard tapping on the "Done" button. In the second window I have a text view, and also here by tapping on "Done" the keyboard is dismissed. The problem is: if I leave the first view without closing the keyboard and I go to the second view, the keyboard is not responding. I can't close it and the button don't work anymore. Where's my mistake? Can I reslove this issue?
I hope you can help me. Thank you so much.
Upvotes: 0
Views: 309
Reputation: 4513
Use Notification design approach to dismiss the current:
create notification and include it in your cancel method or method that switches to another view:
NSNotification *dismissKeyboard = [NSNotification notificationWithName:@"dismissKeyboard" object:nil];
[[NSNotificationCenter defaultCenter] postNotification:dismissKeyboard];
in your second view add a notification listener in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodToExecute) name:@"dismissKeyboard" object:nil];
add method to execute when notification is sent:
-(void)methodToExecute {
[self.textfield resignFirstResponder];
}
Upvotes: 1
Reputation: 9414
You need to simply resignFirstResponder prior to changing views. Do away with your second UIWindow and use only one UIWindow to swap out views. Normally you use 2 viewControllers and change between them but you can also use 2 different UIViews on a UIWindow if you really wanted.
Upvotes: 0