【问题标题】:How can I debug a Swift's function call stack?如何调试 Swift 的函数调用堆栈?
【发布时间】:2018-05-08 00:21:26
【问题描述】:

我有一个屏幕被推送两次的问题。问题是我不知道哪个 pushViewController 正在这样做,而且我有很多。所以我想给navigationController.pushViewController() 函数添加一个断点,这样我就可以看到调用该函数的前一个调用堆栈是什么。我不需要看 pushViewController 的内部。我只需要在调用 navigationController 处的函数 pushViewController 时停止断点。但是我不能在 navigationController 代码的open func pushViewController() 上设置断点。我该怎么做?

【问题讨论】:

    标签: swift xcode debugging breakpoints


    【解决方案1】:

    您可以扩展UINavigationController 并覆盖pushViewController 函数。

    class MyNavigationViewController : UINavigationController {
        override func pushViewController(_ viewController: UIViewController, animated: Bool) {
            super.pushViewController(viewController, animated: animated)
        }
    }
    

    然后,如果您使用故事板,请将导航控制器的类更改为 MyNavigationViewController,如果您从代码创建导航控制器,则还要在代码中。

    【讨论】:

    • 我想避免为此目的扩展 UINavigationController,但我想这是不可避免的。谢谢。
    猜你喜欢
    • 2016-12-13
    • 2018-03-20
    • 1970-01-01
    • 2019-11-22
    • 2015-08-25
    • 2014-11-13
    • 1970-01-01
    • 2017-07-18
    • 2016-11-04
    相关资源
    最近更新 更多