ios - 如何 "virtually"点击导航栏中的后退按钮

标签 ios swift uinavigationcontroller uisegmentedcontrol uicontainerview

我有应用程序,我的导航栏内的分段控件在哪里。在导航栏下我有 3 个容器。在这些容器中,我有 TableView Controller 。如果你点击分段控制,一个 TVC 出现而其他的消失(container1.hidden = true 等等)。

问题是当我按下也在导航 Controller 中的“保存”按钮时 - 按钮不会触发“虚拟按下后退按钮”。

我使用了以下在我的其他项目中有效的代码(它在包含所有容器 View 的 VC 中的按钮操作中)但这次不行:

if let navController = self.navigationController {
   navController.popViewControllerAnimated(true)
}

图像以获得更好的洞察力: enter image description here

更新:感谢@Alexey Bondarchuk 我解决了它。评论可能令人困惑,所以我只是回顾一下问题和解决方案。

最初,我有 ViewController。对于这个 Controller ,我嵌入了导航 Controller 。我将 segues 连接到这个导航 Controller 。那是错误的。 所以我删除了导航 Controller 中的这个嵌入,直接(显示)segues 到我的 View Controller (在屏幕截图上)。这是自动创建的导航栏,我做的最后一件事是将 navigation item 放入其中,所以现在我的代码弹出右侧的 navigationController。希望这是可以理解的。

最佳答案

我有几个想法:

  1. 您的 navigationController 等于“nil”并且 .popViewControllerAnimated 将永远不会被调用。如果您使用的是 UITabBarController,则可能会发生这种情况。在这种情况下,请尝试使用 self.tabBarController?.navigationController 而不是 self.navigationController

  2. 您的 Controller “模态”显示。在这种情况下,您可以尝试调用 navController.dismissViewControllerAnimated 而不是 navController.popViewControllerAnimated

关于ios - 如何 "virtually"点击导航栏中的后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32012102/

相关文章:

swift - 当 UIView 展开时,如何向下移动文本字段(Swift)

ios - 在选项卡栏 Controller 中嵌入 View Controller 会删除导航项

iphone - IPAD APP设计题 - 页面很多,做的很少

ios - 如何将场景切换到导航 Controller 堆栈的几层?

ios - 无法使用Appium Desktop在真实设备上运行WebDriverAgent

ios - 如何获取导航后退按钮标题?

iphone - UIBarButtonItem 外观和 setBackButtonBackgroundImage

ios:不要让当前位置成为 map 上的图钉

ios - 带有链接的警报消息,用于导航到 Swift 应用程序中的不同场景

xcode - swift - 通过prepareforsegue在2个 View Controller 之间添加值