我在我的核心數據存儲(100條)的消息列表最新。CoreData升:是的,顯示從底部
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"created" ascending:YES];
NSArray *sortDescriptors = @[sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchLimit:20];
它只顯示我需要的順序中的前20條消息。 我需要做的是:顯示最後20條消息,按創建日期排序,但它們應該出現在TableView的底部。
Storage:
1 : Test 1
2 : Test 2
3 : Test 3
It shows now as :
1 : Test 1
2 : Test 2
**Supposed to show in table View:**
3 : Test 3
2 : Test 2
1 : Test 1
fetchedResultsController:
- (NSFetchedResultsController *)fetchedResultsController{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Messages" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setFetchLimit:20];
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"created" ascending:YES];
NSArray *sortDescriptors = @[sortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(owner = %@) and (stream == %@) and (topic == %@)", ownerGuid,openStream,currentTopic];
[fetchRequest setPredicate:predicate];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
self.fetchedResultsController.delegate = self;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self.fetchedResultsController performFetch:NULL];
return _fetchedResultsController;
}
你有'(所有者=%@)'的時候,你應該有'(所有者==%@)' – Abizern
是不一樣的? –
一個是賦值運算符,另一個是等於運算符。 – Abizern