实际错误Cannot convert value of type 'UIViewController' to type 'UINavigationController' in coercion
在我进入我的导航之前,在视图控制器的代码中。
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
}
}
我的导航视图控制器类定义为:class DashboardNavViewController: UIViewController {
.它应该被宣布为别的东西吗?
只需替换
var nextViewCont: DashboardNavViewController = segue.destinationViewController as UINavigationController
跟
var nextViewCont = segue.destinationViewController as! DashboardNavViewController
如果你想呈现UINavigationController
那么你的DashboardNavViewController
必须是UINavigationController
的子类,现在是UIViewController
的子类,所以你不能像你的错误所说的那样UINavigationController
投射它。
您的导航视图控制器类应该像下面这样被污损:
class DashboardNavViewController: UINavigationController {