0

i am trying to develop a simple application that shows names from a database made in sqlite3.

It returns an error:

2012-08-21 21:10:43.182 NameDatabase[1325:c07] Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]; /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061 2012-08-21 21:10:43.184 NameDatabase[1325:c07] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

I have tried many things to fix the problem but i am out of ideas.

This is the method i think is causing the problem:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomerCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NameClass *name_class = [self.name_vc objectAtIndex:[indexPath row]];
    cell.textLabel.text = name_class.name;
    //[[cell textLabel] setText:[NSString stringWithFormat:@"%@ ,@%d",name_class.name, name_class.id]];
    return cell;
}
Michel
  • 4,076
  • 4
  • 34
  • 52
uba2012
  • 373
  • 1
  • 3
  • 14

1 Answers1

0

you need to allocate the tableViewCell in case the dequeueReusableCellWithIdentifier:CellIdentifier does not provide you with a non-nil value

    if (!cell) {
    cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
J2theC
  • 4,412
  • 1
  • 12
  • 14
  • okay thanks now at least the window was visible.. but nothing comes up? – uba2012 Aug 21 '12 at 19:29
  • now it says this:2012-08-21 21:30:34.003 NameDatabase[1516:c07] -[NSObject tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6c45420 2012-08-21 21:30:34.004 NameDatabase[1516:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSObject tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6c45420' – uba2012 Aug 21 '12 at 19:31
  • Make sure you are assigning the proper delegate to the tableview. it seems someone is receiving the delegate callbacks when it's not supposed to. – J2theC Aug 21 '12 at 19:48