I have a UIViewController
in which I've embedded UITableView
. Because I don't want the UIViewController
to get too heavy I separated the UITableViewDataSource
and UITableViewDelegate
class ViewController: UIViewController {
@IBOutlet var tableView: UITableView!
var dataSource : UITableViewDataSource!
var tableDelegate: UITableViewDelegate!
override func viewDidLoad() {
super.viewDidLoad()
dataSource = TableViewDataSource()
tableDelegate = TableViewDelegate()
tableView.dataSource = dataSource
tableView.delegate = tableDelegate
// Do any additional setup after loading the view, typically from a nib.
}
}
class TableViewDataSource : NSObject, UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "MyCellIdentifier"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
cell.textLabel?.text = "hello"
cell.detailTextLabel?.text = "world"
return cell
}
}
class TableViewDelegate : NSObject, UITableViewDelegate {
//custom code here if required
}
In my Storyboard, I've created a prototype cell within the UITableView
with the identifier
MyCellIdentifier
I use this identifier to create a cell in my UITableViewDataSource
delegate method.
However, if I start the app, only the text of the left label is displayed. The detail label is not visible.
I looked into the debugger and noticed that detailLabel text is correct. The text of the right label is really "world". However, the label is not visible.
I've done a little bit of research and there has been a similar problem in the past. Whenever the text of the detailLabel was set to nil, it was not visible
However in my example, the text is not nil, it is set to "Detail":
How can I make the right label visible?