1

For an iOS app, I have an UIViewController with an UITextView that uses an inputAccessoryView to keep a view docked to the bottom of the screen (or top of keyboard).

However when I display an UIAlertController, the inputAccessoryView disappears.

 UIAlertController * view =[[UIAlertController alloc]init];
 <Add menuItems>
 [self presentViewController:view animated:YES completion:nil]; <-- inputAccessoryView disappears

I found some stackOverFlow articles that explain how to work around this, but not only they are in Swift, but even translated in Objective-C, it does not work:

UIViewController *objViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[objViewController presentViewController:view animated:YES completion:nil];

How can I keep my input AccessoryView displayed ?

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • That's fine, I have my inputAccessoryView displayed even if keyboard is down. However I want the inputAccessoryView to stay even when showing an UIAlertController. In my current case, the inputAccessoryView disappears and reappears when I close the UIAlertController. – Laurent Crivello Sep 23 '18 at 15:18
  • Even when I remove First Responder of the UITextView, the keyboard disappears but the inputAccessoryView stays. Some apps (e.g. WhatsApp when you delete a message) are capable of keeping this inputAccessoryView when displaying an AlertViewController) – Laurent Crivello Sep 23 '18 at 15:40

1 Answers1

2

Found it by properly translating the Swift answer indicated in the referenced article:

UIViewController *objViewController = [UIApplication sharedApplication].windows.lastObject.rootViewController;
[objViewController presentViewController:view animated:YES completion:nil];
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • Works perfectly! Using [UIApplication sharedApplication].windows.lastObject.rootViewController instead of self when presenting alertControllers prevent inputAccessoryView from being dismissed automatically in JSQMessages Library. – coolcool1994 Dec 30 '19 at 05:36