I get the following error:
* Terminating app due to uncaught exception \'NSInternalInconsistencyException\', reason: \'unable to dequeue a ce
Easiest fix is to just change it to FontCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
As with your current code, you'll have to check to be sure cell
is not nil
if you do this method.
Alternately, you can register a UINib
or Class
at the table level that is tied to @"FontCell"
For example (up in viewDidLoad
):
[self.tableView registerClass: [FontCell class] forCellReuseIdentifier:@"FontCell"];
Then you can do
FontCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FontCell" forIndexPath:indexPath];
The nice thing with this method is that you know that your cell will never be nil
, so you can just immediately begin modifying it.
If using a tableview (not a table view controller) as I was, there are not cells that appear by default.
In the storyboard select the tableview Open the Attributes inspector Change prototype cells from 0 to 1 Select the newly displayed table cell In the Attributes inspector set the Identitifier to "FontCell"
You're using the dequeueReusableCellWithIdentifier:forIndexPath:
method. The documentation for that method says this:
You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.
So here
[self.tableView registerClass: [FontCell class] forReuseIdentifier: @"FontCell"];
I also had such a problem, and the solution I found is:
Go to the Project Navigator and select “ViewController.h”. Append
<UITableViewDelegate, UITableViewDataSource>
after “UIViewController”.