gpt4 book ai didi

ios - 导航栏 :shouldPop is not functioning as expected

转载 作者:行者123 更新时间:2023-11-30 11:46:07 26 4
gpt4 key购买 nike

为了在 UINavigationController 上按下后退按钮时执行一些验证。在网上搜索如何做到这一点后,我决定将 UINavigationController 子类化并实现 UINavigationBarDelegate

这是我的问题:只要我实际上没有实现 UINavigationBarDelegate 协议(protocol)的任何内容,它就会像我使用普通的 UINavigationController 时一样工作。但是当我只实现这个功能时:

    func navigationBar(_ navigationBar: UINavigationBar,
shouldPop item: UINavigationItem) -> Bool {
print(#function)
return true
}

我可以在调试控制台中看到该函数实际上被调用了。但弹出并没有发生,只有后退按钮消失, View 保留在那里。我希望仅使用上面的功能,它仍然可以像以前一样工作(即 View 应该正常弹出)。

任何人都可以看到我丢失的东西吗?

最佳答案

您缺少弹出 View Controller ,请在代码中再添加一行 self.popViewController(animated: true)

func navigationBar(_ navigationBar: UINavigationBar,
shouldPop item: UINavigationItem) -> Bool {
print(#function)
self.popViewController(animated: true)
return true
}

关于ios - 导航栏 :shouldPop is not functioning as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48818838/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com