Efren Efren - 1 year ago 62
iOS Question

SWIFT 3, Eureka: When using a navigation controller, the keyboardWillShow callback is not called


  • NavigationController is a root controller of a TabBarController

  • TabBarController has 2 UIViewControllers

  • One UIViewController has a function that presents another UIViewController

  • UIVIewController that is presented has a StackView

  • Instantiates a subclass of FormController (eg: FormVC) and adds to Stack as subview


function of FormVC does not get called. The keyboard actually adds the input to the row, but the auto scrolling does not happen

Is this only a problem in Eureka or perhaps a problem using the Navigation controller's

Answer Source


The correct way to use the FormVC is with the Container, as per the comment in the question.

Here is a great explanation credit to Miguel Revetria - source, github:

Hi chefren the problem with your approach is that the FormViewController lifecycle is not being handled because you are not adding it to the view controllers hierarchy. Actually you are only adding its view to one of your views.

The function keyboardWillShow is not being called due to the FormViewController adds this observer to the notification Notification.Name.UIKeyboardWillShow from the function viewWillAppear, which in your case is not being called. As this, other stuff may not work properly, because the view controller lifecycle is not being handled.

That is not the way the FormViewController should be used. Using it in that way may end up with an undesired behavior like you experienced. The correct way to embed a FormViewController in other view controller's view is by adding it as a Child View Controller. See this Apple guide for further information Implementing a Container View Controller. Additionally, in storyboards you can use a Container View.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download