I am creating a tableView interface for iOS and I have a UITableView
and a custom UITableViewCell
called BookCell
. When I use self.tableView.reloadData()
on viewDidLoad()
, I receive the error:
Home Connect[896:9320] Unknown class _TtC12Home_Connect8BookCell in Interface Builder file. Home Connect[896:9320] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key BCAuthorLabel.'
This is my custom cell class:
class BookCell: UITableViewCell {
@IBOutlet weak var BCTitleLabel: UILabel!
@IBOutlet weak var BCAuthorLabel: UILabel!
@IBOutlet weak var BCLangLabel: UILabel!
var title: String?{
didSet {
BCTitleLabel.text = "Title: " + title!
}
}
var author: String?{
didSet {
BCAuthorLabel.text = "Author: " + author!
}
}
var lang: String?{
didSet {
BCLangLabel.text = "Language: " + lang!
}
}
}
This is where I access the book cell:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BookCell", for:
indexPath) as! BookCell
print("Index Path: ")
print(indexPath.row)
let b = self.bookArray[indexPath.row]
cell.title = b.title
cell.author = b.author
cell.lang = b.language
return cell
}
And when I add 'self.tableView.reloadData()' to this code, I get the error that I showed above
var bookArray = [Book]()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between
presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the
navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
BookAPI.getAllBooks { (books, error) in
if error == nil{
print("Initial Addition: ")
self.bookArray = books!
print(self.bookArray.count)
self.tableView.reloadData()
}
}
}
I tried using this solution and this one to help, but it did not work. I have set the Module
and Target
, and I verified it in the XML file as well.
Any suggestions on what I can do to fix this?
Here is my connection for the BCAuthorLabel (and all the other labels)
UPDATE: Could this be the issue? These are the connection attributes for the cell