本文介绍了意外的UIPageViewController行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 UIPageViewController 构建应用。它正如我预期的那样工作,直到它到达包含UITextField数量的最后一页。

I'm currently building a app using UIPageViewController. It is working as I expected until it reaches last page which contains numbers of UITextField.

但是当我点击UITextField的一个实例时,它突然跳转到上一页而没有任何理由而不是显示键盘。当我滚动到最后一页并再次点击文本字段时,它运行良好没有任何问题。

But when I tapped one of instances of UITextField, it suddenly jumps to the previous page without any reason instead of showing a keyboard. When I scroll through to the last page and tap a text field again, it works well without any problem.

通过点击链接到最后一页并附加到UIPageViewController实例的导航按钮立即显示最后一页也很好。

It is also fine when it shows last page immediately by tapping the navigation button that links to the last page and that is attached to the UIPageViewController instance.

只有当我从第一页到最后一页滚动页面时才会出现此问题,并且在第一次尝试时只发生一次。

This problem happens only when I scroll through pages from first to the last, and it happens only once at the first try.

我怀疑内存不足,所以我在UIPageViewController实例和最后一个页面视图控制器的 - didReceiveMemoryWarning 方法中设置了断点。但它们从未被调用。

I suspected low memory issues, so I set breakpoints in -didReceiveMemoryWarning method of both UIPageViewController instance and the last page view controller. But they were never called.

第二次尝试是在最后一页视图控制器的 -willMoveToParentViewController中添加了一个断点:方法并将其条件设置为 parent == nil (当它从父视图控制器中删除时,这是有问题的UIPageViewController实例)

The second try is that I added a breakpoint in the last page view controller's -willMoveToParentViewController: method and set its condition to parent == nil(when it's removed from parent view controller, which is the UIPageViewController instance in question)

当我运行应用程序时,断点的调用堆栈表示该方法由UIPageViewController的 -_ flushViewController:animated:调用。

When I run the app, the breakpoint's call stack says that the method is called by UIPageViewController's -_flushViewController:animated:.

我不知道为什么这个-flushViewController:animated:被调用。如果我能找出原因,它将帮助我解决问题。

I don't know why this -flushViewController:animated: is called. If I can figure out the cause, it will help me with fixing the problem.

有没有人可以帮助我?

推荐答案

我'我不确定你的代码中是做什么的,但是调试它的一个可能的方法是尝试捕获 UITextField UIKeyboardWillShowNotification 检查它是否正常触发的事件。

I'm not sure what it is in your code that does this, but one probable approach in debugging this is to try and catch the UITextField's UIKeyboardWillShowNotification event to check if it's firing properly.

还尝试在页面的 viewWillAppear 事件中设置断点,以检查是否所有 UITextField 已经正确实例化了 - 我怀疑在你点击第一个文本字段时并非所有文本字段都已实例化,这意味着接收点击操作的对象将是你的 UIPageViewController 而不是 UITextField

Also try to set a breakpoint at your page's viewWillAppear event to inspect if all of the UITextFields have been instantiated properly -- I would suspect that at the point where you tapped the first text field not all of them have instantiated yet, meaning that the object receiving the tap action will be your UIPageViewController instead of the UITextField.

这篇关于意外的UIPageViewController行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:06