Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何修复';无法强制转换类型为';的值;?_Ios_Swift_Segue - Fatal编程技术网

Ios 如何修复';无法强制转换类型为';的值;?

Ios 如何修复';无法强制转换类型为';的值;?,ios,swift,segue,Ios,Swift,Segue,我对这个错误有意见。如果你继续去我的赛格。有没有办法解决这个问题。非常感谢您的任何帮助 这是我的视图控制器 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { ***let rvc = segue.destinationViewController as! WebViewController*** rvc.currentCollege = currentCollege } 这

我对这个错误有意见。如果你继续去我的赛格。有没有办法解决这个问题。非常感谢您的任何帮助

这是我的视图控制器

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    ***let rvc = segue.destinationViewController as! WebViewController***
    rvc.currentCollege = currentCollege
}
这是我的课:

import Foundation

class College {
    var webView = String()
    var name = String()
    var description = String()
    var location = String()
    var numberOfStudents = String()
    var image = String()


    init(Name n: String,Description d: String,Location l: String,NumberOfStudents s: String,Image i:String, WebView w: String) {
        name = n
        description = d
        location = l
        numberOfStudents = s
        image = i
        webView = w
    }
    init(){
        name = ""
        description = ""
        image = ""
        webView = ""
    }
}

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
        let currentCell = tableView.dequeueReusableCellWithIdentifier("myCell")!
        let currentCollege = collegeArray[indexPath.row]
        currentCell.textLabel!.text = currentCollege.name
        currentCell.detailTextLabel?.text = currentCollege.location
        return currentCell
    }

我猜destinationViewController不是WebViewController。也许WebViewController内嵌在导航控制器中,您可以执行以下操作:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if let rvc = segue.destinationViewController as? WebViewController {
        rvc.currentCollege = currentCollege
    }
}

避免在准备阶段强制下铸

您在WebViewController中的currentCollege类型是什么?currentCollege的类型是什么?这是我在web视图控制器var currentCollege=College()中的内容,currentCollege的价值是什么。你能再添加一些代码吗?还是不清楚…你在哪里申报大学需要更多的代码。我不需要看到实际的类定义。粘贴WebViewController和ViewControlleri的代码如果在类中使用初始值设定项,则不需要像下面这样实例化属性:var webView=String(),只需执行以下操作:var webView:String