i am trying to display content in a custom cell in a table view. I started with a master detail application and tried to customize it. I created a new xib with the custom cell and connected it to a class and created the needed outlets.
This is the MasterView Controller (removed all functions I did not edit)
import UIKit
class MasterViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
var nipName=UINib(nibName: "SimpleTableCell", bundle:nil)
self.tableView.registerNib(nipName, forCellReuseIdentifier: "cell")
self.tableView.registerClass(SimpleTableCell.self, forCellReuseIdentifier: "cell")
//Create Add Button
let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "insertNewObject:")
self.navigationItem.rightBarButtonItem = addButton
loadInitialData()
tableView.reloadData()
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as SimpleTableCell
cell.loadItem(user:"user1", hoop: "hoop1", post: "There is text in the table")
return cell
}
}
This is the Class for the custom cell
import UIKit
class SimpleTableCell : UITableViewCell{
@IBOutlet var userLabel: UILabel
@IBOutlet var hoopLabel: UILabel
@IBOutlet var postLabel: UILabel
func loadItem(#user: String, hoop: String, post: String) {
userLabel = UILabel()
hoopLabel = UILabel()
postLabel = UILabel()
userLabel.text = user
hoopLabel.text = hoop
postLabel.text = post
}
}
However I always get a "can't unwrap optional.none" in the loadItem function as soon as the text of userLabel is about to be changed - I don't get it because I initialise the labels right before I try to add text - or Am I wrong?
Thanks for any help.