繁体   English   中英

无法将类型“ UITableViewCell”的值转换为指定的类型

[英]Cannot convert value of type 'UITableViewCell' to specified type

我刚刚在文件“ Celda”中创建了一个新的自定义单元格,现在我需要使用JSON在UITableView中使用标签。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell : Celda = tableView.dequeueReusableCellWithIdentifier("jsonCell")!
    var dict = arrRes[indexPath.row]
    cell.nombre1.text = dict["nombre"] as? String
    cell.nombre2.text = dict["calle"] as? String
    cell.id.text = dict["id"] as? String
    return cell
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return arrRes.count
}

但是我在“让”行中出现错误。 它说: Cannot convert value of type 'UITableViewCell' to specified type 'Celda'

尝试

let cell = tableView.dequeueReusableCellWithIdentifier("jsonCell") as! Celda
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableView {
        let cell : CustomCell = tblv.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
        cell.photo.image = images[indexPath.row] 
        cell.name.text = names[indexPath.row] as String
        cell.breedName.text = breeds[indexPath.row] as String

   return cell     
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM