Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UITableViewCell not showing labels

I've created custom cell view in 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!

}

then hooked up everything in storyboard, set constraints and registered class: self.tableView.register(FeedCell.self, forCellReuseIdentifier: "Cell")

When I use Subtitle as class of my custom table cell everything works fine, but when I use custom FeedCell in my table cell, label's are not showing, but I am able to select cells.

like image 261
Scripy Avatar asked Jul 09 '26 21:07

Scripy


1 Answers

Try this code to debug connections

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

    }
like image 153
Rishi Chaurasia Avatar answered Jul 11 '26 12:07

Rishi Chaurasia