如何修复'无法转换类型值的错误'?

时间:2016-03-14 19:30:53

标签: ios swift segue

我遇到此错误的问题。如果继续我的segue。有没有办法来解决这个问题。非常感谢任何和所有帮助。

这是我的视图控制器

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
    }

1 个答案:

答案 0 :(得分:2)

我猜测destinationViewController不是WebViewController。也许WebViewController嵌入在导航控制器中你可以做类似的事情:

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

避免在prepareForSegue中强制执行强制转换。