ios - 无法将类型 'UITableViewCell' 的值转换为指定类型

标签 ios swift uitableview

我刚刚在文件“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
}

但我在“let”行中遇到错误。它说:无法将“UITableViewCell”类型的值转换为指定类型“Celda”

最佳答案

尝试

let cell = tableView.dequeueReusableCellWithIdentifier("jsonCell") as! Celda

关于ios - 无法将类型 'UITableViewCell' 的值转换为指定类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35091383/

相关文章:

ios - 2 UITableViewCell 中 UIView 的圆角不起作用

ios - Swift iOS 图表 - 隐藏某些条形图值标签

iphone - 使用 AVAudioRecorder 重新录制

ios - 通过点击 UIButton 重新加载 UIScrollView

ios - UITableViewCell subview 不遵守自动布局约束

ios - 如何在SwiftUI分段选择器中更改选定的分段颜色

swift - 通过Decodable初始化Realm对象

swift - 获取位于 Assets.xcassets 中的数据集中文件的路径

ios - 如何在 swift 中创建一个 UITableView

ios - 在行选择上设置 TableViewCell 标签颜色 Swift 3