iOS – UITableView reloaddata does not reload

I am confused why reloadData does not reload the tableview. It does not call numberOfRowsInSection…

The fetchedResultsController does get the new data after saving the new data to the core data A new row

Before adding new data to the tableview

2011-12-29 19:09:08:213 CaveConditions[56423:71939] FRC 170

After viewWillAppear and add data

2011-12-29 19:09:35:908 CaveConditions[56423:71939] FRC NEW 171 

Before calling reloadData, tableView(aTableView) is not nil

2011-12-29 19:18:27:334 CaveConditions[56525:71939] TableVIew: ; contentOffset: {0, 0}>

Once I restart the app, it shows the new content… I am using Storyboard and have completed all the connections between the tableview and the delegate/data source and checked it many times. Class is a UIViewController.

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.fetchedResultsController = nil;

NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}

id sectionInfo = [[fetchedResultsController sections] objectAtIndex:0];
NSLog(@"FRC NEW %d",[sectionInfo numberOfObjects]);

[self.aTableView reloadData];
}

I don’t know what’s wrong here… Any ideas?

Edit:

I am too lazy to load FRC

- (NSFetchedResultsController *)fetchedResultsController 
{
if (!fetchedResultsController)
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

if (isNormalCell)
{
fetchRequest.entity = [NSEntityDescription entityForName:@"Condition" inManagedObjectContext:self.context];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"diveDate" ascending:NO]];
fetchRequest.predicate = [ NSPredicate predicateWithFormat:@"cave = %@", cave];
} else
{
fetchRequest.entity = [NSEntityDescription entityForName:@"Condition" inManagedObjectContext:self.context];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"insertDate" ascending:NO]];
fetchRequest.returnsDistinctResults = YES;
}
fetchRe quest.fetchBatchSize = 20;


fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil] ;

fetchedResultsController.delegate = self;
}

return fetchedResultsController;
}

Here is some code

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

if (!isNormalCell)
CellIdentifier = @"conditionCellReport";
else
CellIdentifier = @"conditionCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

// Set up the cell...
[self configureCell:cell atIndexPath:indexPath];

return cell;
}


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *) indexPath
{
Condition *condition = [fetchedResultsController objectAtIndexPath:indexPath];

ConditionCell *conCell = (ConditionCell *)cell;

// Reset cell tag which normally contains the ConditionID
conCell.tag = 0;
conCell.img.image = nil;

conCell.lineLabel.text = [condition.line valueForKey:@ "line"];
conCell.flowProgress.progress = [[condition.flow valueForKey:@"flowValue"] floatValue];
conCell.percolationProgress.progress = [[condition.percolation valueForKey:@"percolationValue "] floatValue];
conCell.sedimentProgress.progress = [[condition.sediment value ForKey:@"sedimentValue"] floatValue];
conCell.visProgress.progress = [[condition.visibility valueForKey:@"visValue"] floatValue] / 25;
conCell.tag = [condition.ccId intValue ];
...

Found another problem. Save the data and return to the tableview when trying to scroll. It only shows white cells.. It also does not reload the old cells.< /p>

Good! I found this problem. I use beginUpdates and endUpdates instead of reloadData. Thank you very much for your help! I got information from NSFetchedResultsControllerDelegate Reference

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates] ;
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}

I am confused why reloadData does not reload the tableview. It does not call numberOfRowsInSection…

The fetchedResultsController does get the new data after saving it to the core data A new row

Before adding new data to the tableview

2011-12-29 19:09:08:213 CaveConditions[56423:71939] FRC 170

After viewWillAppear and add data

2011-12-29 19:09:35:908 CaveConditions[56423:71939] FRC NEW 171 

Before calling reloadData, tableView(aTableView) is not nil

2011-12-29 19:18:27:334 CaveConditions[56525:71939] TableVIew: ; contentOffset: {0, 0}>

Once I restart the application, it will show Show new content… I am using Storyboard and have completed all the connections between tableview and delegate/data source and checked it many times. Class is a UIViewController.

- (void )viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.fetchedResultsController = nil;

NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]) ;
}

id sectionInfo = [[fetchedResultsController sections] objectAtIndex:0];
NSLog(@"FRC NEW %d",[sectionInfo numberOfObjects]);

[self.aTableView reloadData];
}

I don’t know what’s wrong here… Any ideas?

Edit:

I am too lazy to load FRC

- (NSFetchedResultsController *)fetchedResultsController 
{
if (!fetchedResultsController)
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

if (isNormalCell)
{
fetchRequest.entity = [NSEntityDescription entityForName:@"Condition" inManagedObjectContext:self.context];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"diveDate" ascending:NO]];
fetchRequest.predicate = [ NSPredicate predicateWithFormat:@"cave = %@", cave];
} else
{
fetchRequest.entity = [NSEntityDescription entityForName:@"Condition" inManagedObjectContext:self.context];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"insertDate" ascending:NO]];
fetchRequest.returnsDistinctResults = YES;
}
fetchReques t.fetchBatchSize = 20;


fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil] ;

fetchedResultsController.delegate = self;
}

return fetchedResultsController;
}

Here is some code

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

if (!isNormalCell)
CellIdentifier = @"conditionCellReport";
else
CellIdentifier = @"conditionCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

// Set up the cell...
[self configureCell:cell atIndexPath:indexPath] ;

return cell;
}


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Condition *condition = [fetchedResultsController objectAtIndexPath:indexPath];

ConditionCell *conCell = (ConditionCell *)cell;

// Reset cell tag which normally contains the ConditionID
conCell.tag = 0;
conCell.img.image = nil;

conCell.lineLabel.text = [condition.line valueForKey:@"line"] ;
conCell.flowProgress.progress = [[condition.flow valueForKey:@"flowValue"] floatValue];
conCell.percolationProgress.progress = [[condition.percolation valueForKey:@"percolationValue"] floatValue] ;
conCell.sedimentProgress.progress = [[condition.sediment valueForKey: @"sedimentValue"] floatValue];
conCell.visProgress.progress = [[condition.visibility valueForKey:@"visValue"] floatValue] / 25;
conCell.tag = [condition.ccId intValue];
...

I found another problem. Save the data and return to the tableview when trying to scroll. It only shows white cells.. It also won’t reload the old cells.

Good! I found this problem. I use beginUpdates and endUpdates instead of reloadData. Thank you very much for your help! I got information from NSFetchedResultsControllerDelegate Reference

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates] ;
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3880 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.