オンとオフのモードを備えたアプリがあります。オンライン モードでは、サーバーへのログインを確認し
、XML ファイルをダウンロードしてそのファイルを解析しています。すべてのデータは coreData に書き込まれます。
TableView に NSFetchedResultsController を設定しています。
オフ モードを使用する場合 (オフライン モードを使用するには、coreData エンティティを nil にしないでください)、
ビューを閉じて、coreData からのデータを含む tableView を表示します。
問題は次のとおりです。オフライン モードを使用すると、データが正しく並べ替えられません。
reloadData は機能しません。何度も試しました。
どうすればtableViewをリロードできるので、オフモードでもデータを正しくソートできますか??
編集1:
オフモードでは、これだけを行います:
if (xmlFile) {
//FadeOut animation nach erfolgreichem Login
//und removeFromSuperview
[UIView animateWithDuration:0.8
animations:^{loginView.alpha = 0.0;}
completion:^(BOOL finished){ [loginView removeFromSuperview]; }];
}
viewDidAppear でテーブルビューをソートするにはどうすればよいですか?
編集2:
ここに私の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;
}