Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode error: unable to dequeue a cell with identifier MealTableViewCell

Tags:

xcode

ios

swift

I have been following the apple tutorial here and have come across an error:

2016-01-12 09:34:32.909 FoodTracker[1812:124509] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier MealTableViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

The error appears when the program is run, and the red highlighted line appears on the class line of AppDelegate.swift

These are the lines of code I believe are causing the error, as I found out through breakpoints:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellIdentifier = "MealTableViewCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MealTableViewCell

    // Configure the cell...
    let meal = meals[indexPath.row]

    cell.nameLabel.text = meal.name
    cell.photoImageView.image = meal.photo
    cell.ratingControl.rating = meal.rating


    return cell

}

I have looked around online, and a lot of answers have said to ensure that the TableCell has an identifier, however mine does and the error still pops up.

Please let me know if I need to post any more info.

Thanks in advance

like image 343
demar Avatar asked Jan 11 '16 20:01

demar


1 Answers

This works for me..

my Scene

Attributes inspector

and I'm using a different identifier, "DeviceDetailsCell"

let cellIdentifier = "DeviceDetailsCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! DeviceDetailsTableViewCell
like image 184
Jan Avatar answered Sep 29 '22 11:09

Jan