ios - UITableViewCell 初始化失败 (Swift)

标签 ios swift uitableview

我正在使用 tableView并尝试创建我的 cells ..徒劳。 我设置了我们必须做的所有事情(创建了一个原型(prototype)单元,给出了一个标识符(“CustomerCell”),在 delegatedataSource 中设置了 storyBoardViewDidLoad,设置了良好的类在 StoryBoard 中为 tableViewcells 等)。

这是我的代码:

override func viewDidLoad() {

    self.tableView.delegate = self
    self.tableView.dataSource = self
}


 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let item = items[indexPath.section]
    switch item.type {

    case .customer:

        if let cell = tableView.dequeueReusableCell(withIdentifier: "CustomerCell", for: indexPath) as? CustomerCellSetter {
            cell.item = item as? Customer // THIS is never called, the cell return nil all the time
            return cell
        }

    return UITableViewCell()
 }

cell ID

Delegates

方程式中是否还有其他参数可以获取我的细胞? 预先感谢您的宝贵帮助!

编辑:

这是我的UITableViewCell类(class):

class CustomerCellSetter: CustomerTableViewCell {
var item: Customer? {
    didSet {
        guard let item = item else {
            return }
        if let firstName = item.firstName {
            fisrtName?.text = firstName
        }

        if let theLastName = item.lastName {
            lastName.text = theLastName
        }

        if let theGsm = item.GSM {
            gsm.text = theGsm
        }

        if let theMail = item.mail {
            mail.text = theMail
        }

        if let theAdress = item.adress {
            adress.text = theAdress
        }

        if let theNote = item.notes {
            notes.text = theNote
        }

    }
}

}




class CustomerTableViewCell: UITableViewCell {


@IBOutlet var fisrtName : UILabel!
@IBOutlet var lastName : UILabel!
@IBOutlet var gsm : UILabel!
@IBOutlet var mail : UILabel!
@IBOutlet var adress : UILabel!
@IBOutlet var notes : UILabel!




override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}

}

编辑2:

enter image description here

最佳答案

您是否将单元格的类设置为“CustomerCellSetter”?

这可以在身份检查器中完成。

关于ios - UITableViewCell 初始化失败 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51348160/

相关文章:

ios - 打开Health通过URL Scheme去一个App的权限

ios - 为什么 HTML5 Media Source 视频不能在 IOS 上运行?

ios - 如何在本地运行 TestFlight 构建

iphone - iOS:如何动态设置 UITableView 的高度

iphone - 切换 View 时黑屏

ios - SCNNode 放置后不服从位置

cocoa - NSDocument 不接收 printOperationWithSettings

swift - 截断 NSTextField 的最后一个可见行

iphone - 同步访问 UITableViewDelegate 逻辑

ios - 适用于 iOS 的 Swift TableView