导航后导航栏损坏

Posted

技术标签:

【中文标题】导航后导航栏损坏【英文标题】: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.

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

【问题讨论】:

【参考方案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。

以上是关于导航后导航栏损坏的主要内容,如果未能解决你的问题,请参考以下文章

Bootstrap 4 导航栏切换损坏

UIViewController 导航 - 在意外状态下完成导航转换。导航栏子视图树可能会损坏

导航栏在 Chrome 中损坏,而不是在 IE 或 Firefox 中

嵌套推送动画可能导致导航栏损坏多次警告

iOS:嵌套推送动画可能导致导航栏损坏

Twitter Bootstrap 响应式导航栏在小屏幕上损坏