【问题标题】:Corrupted navigation bar after navigating导航后导航栏损坏
【发布时间】:2016-06-07 20:30:07
【问题描述】:

这是目前的情况:

UITabBarController
    UINavigationController
        UIPageViewController
            Some UIViewControllers (the actual content)

所以 UIPageViewController 包含一些 UIViewControllers,它们都包含一个 UITableView。

当我单击 UITableView 中的某一行时,UIViewController 会调用 didSelect 方法。该方法如下所示:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
    let activity = self.activities[indexPath.row - 1]
    self.delegate?.dayTableViewSelectedActivity(activity, sender: self)
}

然后 UIPageViewController 已经实现了协议,因此正在调用委托方法。该方法如下所示:

func dayTableViewSelectedActivity(activity: Activity, sender: DayTableViewController) {
    self.performSegueWithIdentifier("openDetails", sender: activity)
}

然后应用导航(推送)到 DetailViewController。当我向后滑动(默认 iOS 行为)时,DetailViewController 立即弹出到 UIPageViewController,没有动画。然后我的导航栏坏了,并且包含一个不属于那里的后退按钮,因为我无法再返回了。

当我再次单击一个单元格时,控制台会给我一个nested push animation can result in corrupted navigation bar 消息。我从那里采取的每一个操作都会给我带来更多控制台错误,例如:

nested pop animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

这个错误让我沮丧了好几个小时,我不知道我做错了什么。没有双重选择。我检查了很多次。希望大家能帮帮我。

【问题讨论】:

    标签: ios swift uinavigationcontroller uipageviewcontroller


    【解决方案1】:

    又挣扎了几个小时,我在这里找到了答案:Pop animation is not working in first UINavigationController of UITabbarController

    我确实有一个覆盖viewDidAppear 方法的 UITTabBarController 的子类。我添加了super.viewDidAppear,现在一切正常。

    【讨论】:

      【解决方案2】:

      您需要确保在导航回 PageViewController 时使用 Unwind Segue。这会将 TableViewController 从堆栈顶部弹出并返回到 PageViewController。这是一篇关于如何在 Swift 中使用它的不错的文章”

      https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/

      【讨论】:

      • 谢谢!我回家后会试试这个。我会及时通知你。
      • 不幸的是它没有用。在本教程中,他们以编程方式进行了 unwind segue。但我只想要默认的 iOS 行为(当您在 UINavigationController 中向右滑动时,您会转到上一个视图控制器)......所以当我在 DetailViewController 中向右滑动时,我想回到 UIPageViewController。
      猜你喜欢
      • 2018-10-07
      • 2013-10-31
      • 2015-04-05
      • 2014-10-16
      • 2023-03-09
      • 1970-01-01
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多