bhavya kothari
bhavya kothari

Reputation: 7474

How to make simple table view using .xib or nib in iOS 6 and xcode 4.5?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier            forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    NSString *currentNames = [nameKeys objectAtIndex:indexPath.row];
    [cell.textLabel setText:currentNames];

    return cell;
   }

Why I am getting below error (I am using .XIB and not storyboards iOS 6 and Xcode 4.5). I do have connected datasource and delegate from connection inspector ot files owner.



Error :

 Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
    2012-12-27 11:35:45.146 TableViewWithXib[570:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

Upvotes: 1

Views: 1261

Answers (1)

Breakpoint
Breakpoint

Reputation: 1541

According to the docs,

You must register a class or nib file using the 
registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: 
method before calling,

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Therefore, if you aren't doing that with a nib file, then using

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];

i.e; without the forIndexPath:indexPath would also work.

Upvotes: 1

Related Questions