我是 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 菜单的图片
最佳答案
从错误日志来看,您似乎没有将 UINavigationController
作为初始 Controller 嵌入到 Storyboard中。
所以首先设置UINavigationController
作为初始 Controller 。
因为 push
和 pop
操作仅在有可用的导航堆栈时执行。
- 根据屏幕截图选择 Storyboard 中的第一个 ViewController。
- 然后是编辑器 -> EmbedIn -> NavigationController
要了解导航堆栈的工作原理,请查看此 link .
将 Navigation 设置为 InitialViewController 后,然后将要首先显示的第一个 View Controller 设置为该导航 Controller 的 rootViewController。
然后你可以将 push 从 button 拖到 secondViewController 以从 firstViewController 推送到 secondViewController。
正如您在屏幕截图中看到的那样,Push(Deprecated)
,因此您必须使用Show
关系。 Show
也执行与 Push
相同的操作。
更新:
根据您的问题更新,您面临无法显示其他 Action Segue 的问题。请按照以下步骤使其可用。
- 在 Storyboard中选择您的导航 Controller 。
- 在右侧面板的
Interface Builder Document
下启用Use Trait Variations
选项。
有关更多详细信息,请查看此 thread .
关于ios - 将 Action Segue 从按钮推送到 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49034098/