ios - 尝试 Seque 到导航 View Controller 时出错无法将类型 'UIViewController' 的值转换为强制类型 'UINavigationController'

标签 ios swift

实际错误是无法将类型“UIViewController”的值转换为强制类型“UINavigationController”

在我转到我的导航之前,在 View Controller 的代码中。 View Controller 我的准备中有以下代码

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "SegueAfterJoin2") {
       // NOTE! THIS IS TWEAKED with "as UINavigationController"
        var nextViewCont:DashboardNavViewController = segue.destinationViewController as UINavigationController;

        // PASS VARS FROM THIS VIEW TO NEXT
        nextViewCont.passedPassword_toViewDashboard = passedPassword_toView2
        nextViewCont.passedEmail_toViewDashboard = passedUsername_toView2
        nextViewCont.passedUsername_toViewDashboard = passedEmail_toView2
        nextViewCont.passedFocus_toViewDashboard = selectedFocus

    }
}

我的导航。 View Controller 类定义如下:class DashboardNavViewController: UIViewController {。它应该声明为其他东西吗?

最佳答案

只是替换

var nextViewCont: DashboardNavViewController = segue.destinationViewController as UINavigationController

var nextViewCont = segue.destinationViewController as! DashboardNavViewController

如果你想呈现 UINavigationController 那么你的 DashboardNavViewController 必须是 UINavigationController 的子类,它现在是 UIViewController 的子类 所以你不能像你的错误所说的那样将它转换为 UINavigationController

你的导航 View Controller 类应该如下所示:

class DashboardNavViewController: UINavigationController {

关于ios - 尝试 Seque 到导航 View Controller 时出错无法将类型 'UIViewController' 的值转换为强制类型 'UINavigationController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36172766/

相关文章:

ios - Xcode 6 标准架构不包括 armv7s

ios - 动态添加 UILabels 到 UIView

swift - 如何在 Xcode、Swift 中使用按钮创建相同的对象

ios - 过滤 TableView 时 UISearchField 出现问题

swift - 当数量超出 Swift 语言允许的最大数量时管理应用程序崩溃

ios - 如何调整/缩放 MTLTexture

ios - 两次之间的分钟数

ios - 在 Parse 中使用 FBgraphUser 从 Facebook 获取用户电子邮件

ios - UISlider 无法在 UITableViewCell 内工作

objective-c - presentModalViewController 不显示 naviagionbar