ios - 将 Action Segue 从按钮推送到 UIViewController

标签 ios swift segue

我是 iOS 应用程序开发的新手,目前面临从 UIButton 到 UIViewController 的一些问题。我在上面的 Main.storyboard 中做了:

  • 选择 UIButton
  • 按住“control”并拖动到 UIViewController
  • 在 Action Segue 下选择“push”

运行后出现以下错误

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

需要帮助解决上述错误。如果解决方案带有屏幕截图,我将不胜感激,因为我是新手。谢谢!

实现@technerd解决方案后,还是不行。下面是 Navigation Controller 菜单和 Action Segue 菜单的图片

enter image description here

enter image description here

最佳答案

从错误日志来看,您似乎没有将 UINavigationController 作为初始 Controller 嵌入到 Storyboard中。

所以首先设置UINavigationController作为初始 Controller 。 因为 pushpop 操作仅在有可用的导航堆栈时执行。

  1. 根据屏幕截图选择 Storyboard 中的第一个 ViewController。
  2. 然后是编辑器 -> EmbedIn -> NavigationController

要了解导航堆栈的工作原理,请查看此 link .

enter image description here

将 Navigation 设置为 InitialViewController 后,然后将要首先显示的第一个 View Controller 设置为该导航 Controller 的 rootViewController。

enter image description here

然后你可以将 push 从 button 拖到 secondViewController 以从 firstViewController 推送到 secondViewController。

enter image description here

正如您在屏幕截图中看到的那样,Push(Deprecated),因此您必须使用Show 关系。 Show 也执行与 Push 相同的操作。

更新:

根据您的问题更新,您面临无法显示其他 Action Segue 的问题。请按照以下步骤使其可用。

  1. 在 Storyboard中选择您的导航 Controller 。
  2. 在右侧面板的 Interface Builder Document 下启用 Use Trait Variations 选项。

enter image description here

有关更多详细信息,请查看此 thread .

关于ios - 将 Action Segue 从按钮推送到 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49034098/

相关文章:

ios - 适用于 iPhone 的真实表格组件

IOS Xcode 验证 Xcode.app

ios - 自发的 Swift 编译器错误

swift - 没有在最后一个 ScoreViewController Swift 上显示分数

ios - Swift:如何将 UITableView 链接到单个 UIDetailView 页面

ios - 如何在 iOS 中捕获 RNBlurModalView 关闭时的事件

ios - 如何在 ios 中维护登录 session ?

ios - 在 FaSTLane/Gym 中将内部版本号传递给 xcargs

ios - 我们如何使用 Moya 调试/查看通过 API 设置的请求?

xcode - 准备将按钮命令发送到另一个 ViewController Swift