0
votes

i am developing a view which contains a grouped UITableView and uses a XMLparser to get its data.

my XMLParser stores NSDictionary data in a NSArray.

in cellForRowAtIndexPath i wrote this in order to populate the UITableView dynamically:

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellArticle";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}
//configuration cellule

if(mParser.summaryArray == nil||[mParser.summaryArray count]==0)
{
//do nothing
}
else {
NSDictionary *sommaire=[mParser.summaryArray objectAtIndex:0];
cell.textLabel.text=[NSString stringWithFormat:@"%@",[sommaire objectForKey:kArticle]];
[mParser.summaryArray removeObject:[mParser.summaryArray objectAtIndex:0]];
}


return cell;
}

The problem is that when the view is loaded, cells are correctly set but when i scroll my table down cells get mixed and some of them are missing. Also when i reach the table limit it crashes and returns this error:

* Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'**

What may be the problem any idea please?

1

1 Answers

0
votes

Instead of your // do nothing, wouldn't your rather do a return nil; there? Otherwise you simply return a cell that is filled with blank label text.

Edit

Can you add a NSLog() here:

cell.textLabel.text=[NSString stringWithFormat:@"%@",[sommaire objectForKey:kArticle]];
NSLog(@"kArticle = '%@' text = '%@'", kArticle, cell.textLabel.text);
[mParser.summaryArray removeObject:[mParser.summaryArray objectAtIndex:0]];