SWIFT3、Eureka:使用导航控制器时,不调用keyboardWillShow回调

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

场景

问题

FormVC 的 keyboardWillShow 函数没有被调用。键盘实际上将输入添加到行中,但不会发生自动滚动

这只是 Eureka 中的问题还是使用导航控制器的 pushViewController 的问题?

回答

根据问题中的评论,使用 FormVC 的正确方法是使用 Container。

这是对 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