将 Action Segue 从按钮推送到 UIViewController

Push Action Segue from button to UIViewController

我是 iOS 应用程序开发的新手,目前面临从 UIButton 到 UIViewController 的一些问题。我在 Main.storyboard 中通过以下方式完成了上述操作:

在 运行 之后,我遇到以下错误

*** 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 菜单的图片

从错误日志来看,您似乎没有将 UINavigationController 作为初始控制器嵌入到故事板中。

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

    根据屏幕截图,
  1. Select 首先 ViewController 在 Storyboard 中。
  2. 然后是编辑器 -> EmbedIn -> NavigationController

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

将 Navigation 设置为 InitialViewController 后,然后将要首先显示的第一个 viewcontroller 设置为该导航控制器的根 ViewController。

然后你可以将 push from button 拖到 secondViewController 以从 firstViewController 到 secondViewController.

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

相同的操作

更新:

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

  1. Select 情节提要中的导航控制器。
  2. 在右侧面板的 Interface Builder Document 下启用 Use Trait Variations 选项。

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

将导航控制器添加到您的初始视图

  1. Select初始视图
  2. 转到编辑器--> 嵌入--> 导航控制器.

Push segues 仅在 UINavigationController 类型中可用。 尝试添加 UINavigationController。 一个简单的方法是: