Using a UITableView
and its UITableViewCell
(s) in Swift. I have some problem showing the detailTextLabel
field of a UITableViewCell
.
I already found these two helpful posts, but could not get a fully working solution: swift detailTextLabel not showing up How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?
Here is the code I am using, relevant to my question:
override func viewDidLoad() {
super.viewDidLoad()
………….
theTableView = UITableView(frame: tmpFrame)
………….
theTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
theTableView.dataSource = self
theTableView.delegate = self
self.view.addSubview(theTableView)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
cell.backgroundColor = UIColor.clearColor()
cell.textLabel?.text = "THE-TEXT-LABEL"
cell.detailTextLabel?.text = "KIJILO" // This does not show up.
return cell
}
When I try to make use of the detailTextLabel
field of UITableViewCell
, it does not show up. Searching on the net, I understand that I have to use the proper style(UITableViewCellStyle
) for the cell, but I do not see how to integrate that change into my code. The examples I've seen are based on subclassing UITableViewCell
and I suppose I do not need to subclass UITableViewCell
only to make use of the detailTextLabel
field. Please tell me if I am wrong.
I have also tried a few things from the posts mentioned above, but nothing works as I want.