0

Scenario

  • 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

Problem

The keyboardWillShow 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 pushViewController?

Community
  • 1
  • 1
Efren
  • 4,003
  • 4
  • 33
  • 75
  • Need to test if it is possible to add the Notification Observer when pushing: http://stackoverflow.com/questions/37825327/swift-3-nsnotificationcenter-keyboardwillshow-hide – Efren May 16 '17 at 06:33
  • Posted to Eureka issue list: https://github.com/xmartlabs/Eureka/issues/1045 – Efren May 16 '17 at 06:59
  • Because the FormVC is just instantiated within another VC, it seems something gets lost. Managed to have it working properly when being set in the Storyboard within a ContainerView's, as the ViewController class type. – Efren May 21 '17 at 23:55

1 Answers1

0

Answer

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.

Regards

Efren
  • 4,003
  • 4
  • 33
  • 75
  • Still getting this message on the console might mean I need to add the keyboardWillHide notification pass: `Reading from private effective user settings.` – Efren May 17 '17 at 00:44