Reputation: 143
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.
Upvotes: 3
Views: 1501
Reputation: 528
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
}
Upvotes: 1