Reputation: 2359
I've ran into quite an unfortunate bug in iOS 9. It seems that when you set a UITextField.inputAccessoryView
, that view's viewWillDisappear:
and viewDidDisappear:
methods are called prematurely (right when the keyboard finishes animating up).
I've included a gif to demonstrate the issue. When the view turns red is when its viewWillDisappear:
method has been called. Oddly when you dismiss the keyboard, viewWillDisappear:
and viewDidDisappear:
are called again. However, viewWillAppear:
is only called once.
Has anyone run into a similar issue? I use viewWillDisappear:
and viewDidDisappear:
to wind down the controller, and obviously an early call is causing unwanted behaviour.
Note: Below is how I create and set the accessory view. Nothing notable in AccessoryViewController.m. Reproduced the issue in a clean project. And it is not present on iOS 8.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (self.textField.inputAccessoryView == nil) {
self.textField.inputAccessoryView = self.vc.view;
}
return YES;
}
- (UIViewController *)vc {
if (!_vc) _vc = [[AccessoryViewController alloc] init];
return _vc;
}
Upvotes: 3
Views: 599
Reputation: 12272
The AccessoryViewController
is not stored strongly on the ViewController. Store it in an instance variable so it does not get cleaned up.
My solution (Swift):
var accessoryView: AccessoryViewController! // works
vs
weak var accessoryView: AccessoryViewController!
Upvotes: 0