Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:
You're using the dequeueReusableCellWithIdentifier:forIndexPath:
method. The documentation for that method says this:
Important: You must register a class or nib file using the
registerNib:forCellReuseIdentifier:
orregisterClass:forCellReuseIdentifier:
method before calling this method.
You didn't register a nib or a class for the reuse identifier "Cell"
.
Looking at your code, you seem to expect the dequeue method to return nil
if it doesn't have a cell to give you. You need to use the dequeueReusableCellWithIdentifier:
for that behavior:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Notice that dequeueReusableCellWithIdentifier:
and dequeueReusableCellWithIdentifier:forIndexPath:
are different methods. See doc for the former and the latter.
If you want to understand why you'd want to ever use dequeueReusableCellWithIdentifier:forIndexPath:
, check out this Q&A.
Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
My bad! It seems to be you are using dequeueReusableCellWithIdentifier:forIndexPath:
method for dequeueing cell. Please try dequeueReusableCellWithIdentifier:
instead and it should work.
dequeueReusableCellWithIdentifier:forIndexPath:
expects a nib file or a registered class for dequeueing cells but you are using storyboard prototype cell. And dequeueReusableCellWithIdentifier:
is guaranteed to return a cell from storyboard if you use correct identifier.
Hope it helps.
Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2903.23/UITableView.m:5261
When creating a view controller than inherits from UITableViewController the following methods are already included:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
If you are not using Dynamic Prototypes then these methods aren't needed and should be deleted.
When your tableview is loading it is calling cellForRowAtIndexPath
(if numberOfSectionsInTableView
and numberOfRowsInSection
are returning a number that isn't 0) which is trying to create a cell with an identifier of "Cell". It can't find a prototype cell with this identifier because you have set the table to use static cells instead and so you get the exception.
Strange UITableView error: Assertion Failure on dequeuing static cells in storyboard
If you are attempting to use a static layout for a table view, you typically do not implement tableView:cellForRowAtIndexPath:
, the UITableViewController
does this for you. It is invalid to call the dequeueReusableCellWithIdentifier:forIndexPath:
method for a statically configured UITableView
(as the error indicates).
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit/UIKit-2935.137/UITableView.m:6509
[self.YOURTABLEVIEW registerNib:[UINib nibWithNibName:@"YOURCUSTOMCELL" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"YOURCUSTOMCELL_IDENTIFIER"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YOURTABLEVIEWCELL_CLASS *cell = [tableView dequeueReusableCellWithIdentifier:@"YOURTABLEVIEWCELL_IDENTIFIER"];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"YOURTABLEVIEWCELL_IDENTIFIER" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
// here write your cell coding like give value to your lable, image , etc.
return cell;
}
Related Topics
How to Detect First Time App Launch on an Iphone
Swift Png Image Being Saved With Incorrect Orientation
How to Validate an Url on the Iphone
How to Select Multiple Images from Uiimagepickercontroller
Ios App Submission: Missing 64-Bit Support
How to Programmatically Scroll Through a Collection View
Uitapgesturerecognizer - Make It Work on Touch Down, Not Touch Up
How to Apply a Perspective Transform to a Uiview
Error: 'Flutter/Flutter.H' File Not Found When Flutter Run on Ios
Save String to the Nsuserdefaults
Nsoperation VS Grand Central Dispatch