i have an app with an On and Off Mode.
In Online Mode, i am checking a login to a server,
downloading an XML-File and parsing that File. All Datas are written to coreData.
I am populating my TableView with NSFetchedResultsController.
If i use the Off Mode (To use the Offline mode, the coreData Entitys should not be nil),
i just dismiss the view to display the tableView with the data from coreData.
Problem here is: The data is not sorted correctly if i use the Offline Mode.
reloadData doesn't work, i have tried it more Times.
How can i relaod the tableView, so i get the data correctly sorted in off mode, too??
Edit 1:
In Off mode i only do this:
if (xmlFile) {
//FadeOut animation nach erfolgreichem Login
//und removeFromSuperview
[UIView animateWithDuration:0.8
animations:^{loginView.alpha = 0.0;}
completion:^(BOOL finished){ [loginView removeFromSuperview]; }];
}
How can i do sort the tableview on viewDidAppear?
Edit 2:
Here my NSFetchedResultsController:
#pragma mark - Fetched results controller
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil)
{
return __fetchedResultsController;
}
/*
Set up the fetched results controller.
*/
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"EntitySetsCards" inManagedObjectContext:self.managedObjectContext];
NSPredicate *inboxPred = [NSPredicate predicateWithFormat:@"archived == 0"];
[fetchRequest setEntity:entity];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
[fetchRequest setPredicate:inboxPred];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptorSetOrder = [[[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES] autorelease];
NSSortDescriptor *sortDescriptorColorOrder = [[[NSSortDescriptor alloc] initWithKey:@"colorOrder" ascending:YES] autorelease];
NSSortDescriptor *sortDescriptorSortOrder = [[[NSSortDescriptor alloc] initWithKey:@"sortingOrder" ascending:YES] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptorSetOrder, sortDescriptorSortOrder, sortDescriptorColorOrder, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
// nil for section name key path means "no sections".
// cacheName auf nil gesetzt, da @"Root" fehler erzeugt hat (FATAL ERROR)
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"setTitle" cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error])
{
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
allFetchedCards = aFetchedResultsController;
allCards = [__fetchedResultsController fetchedObjects];
return __fetchedResultsController;
}