自定义UITableViewCell不显示标签

时间:2017-11-03 12:14:29

标签: ios objective-c swift uitableview

我在Xcode中创建了自定义单元格视图:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedCell

        let iniStr = self.tableArray[indexPath.row]

        let fullNameArr = iniStr.components(separatedBy: "||1||")
        let daFirst = fullNameArr[0]
        let daSecond = fullNameArr[1]

        let finalco = daSecond.components(separatedBy: "||2||")
        let fString = finalco[0]

        cell.questionLabel?.text = daFirst
        cell.answerLabel?.text = daSecond

        return cell
    }

class FeedCell: UITableViewCell {

    @IBOutlet weak var questionLabel: UILabel!
    @IBOutlet weak var answerLabel: UILabel!

}

然后连接故事板中的所有内容,设置约束和注册类:self.tableView.register(FeedCell.self, forCellReuseIdentifier: "Cell")

当我使用Subtitle作为我的自定义表格单元格的类时,一切正常,但是当我在表格单元格中使用自定义FeedCell时,标签没有显示,但我可以选择单元格。

1 个答案:

答案 0 :(得分:1)

尝试使用此代码调试连接

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedCell

        let iniStr = self.tableArray[indexPath.row]
        print(iniStr)

        let fullNameArr = iniStr.components(separatedBy: "||1||")
        let daFirst = fullNameArr[0]
        let daSecond = fullNameArr[1]
        print(daFirst)
        print(daSecond)

        let finalco = daSecond.components(separatedBy: "||2||")
        let fString = finalco[0]

        cell.questionLabel?.text = daFirst
        cell.answerLabel?.text = daSecond

        cell.questionLabel.backgroundColor = .red
        cell.answerLabel.backgroundColor = .green




        return cell

    }
相关问题