0

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

Community
  • 1
  • 1
dl14
  • 19
  • 6
  • provide code, please – JuicyFruit May 12 '17 at 08:40
  • Made edits to my original post – dl14 May 12 '17 at 14:19
  • your code is ok, the problem is with Storyboard. it is not about connection, but some problem in attributes inspector of `Cell` or `Label` – JuicyFruit May 12 '17 at 14:46
  • Can you check the most updated image I posted, I see "!" and I don't think I should.. – dl14 May 12 '17 at 16:05
  • okey, yes, left side should be the name of outlet inside custom class and right is destination class (`BookCell`) – JuicyFruit May 12 '17 at 17:13
  • How do I change this though? It was default when I added a label to the cell on my storyboard and then connected it (by ctrl+drag to the book cell class). The image I have shown on the post is what gets shown when I click on the cell. When I click on the label (inside the cell) I see: BCAuthorLabel -> BookCell – dl14 May 12 '17 at 19:04

0 Answers0