我有一个用 NSFetchedResultsController 填充的表格视图。
我didSelectRowAtIndexPath
正在更新当前的row
. 这里的排序不应该改变。所选行的不同之处在于,我将其标记为已读。没有标题更改或其他内容。
在 iOS4 中,该行被更新并仍然留在他当前的位置,它不会移动到部分的末尾。那是正确的方法。
在 iOS5 中,该行也得到更新,但它移动到该部分的末尾。我想阻止这种情况。我怎样才能做到这一点?为什么会这样?
查看我的代码:
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil)
{
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"EntitySetsCardsInbox" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *inboxPred = [NSPredicate predicateWithFormat:@"archived == 0 AND cardId != 0"];
[fetchRequest setPredicate:inboxPred];
if (sortString == nil) {
//sortString = [[NSString alloc] initWithString:@"sortingOrder"];
sortString = [[NSString alloc] initWithString:@"colorOrder"];
sortAsc = NO;
}
if ([sortString isEqualToString:@"cardTitle"]) {
NSSortDescriptor *sortDescriptor2 = [[[NSSortDescriptor alloc] initWithKey:sortString ascending:sortAsc selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor2, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
XLog(@"sortDescriptors: %@", sortDescriptors);
} else {
NSSortDescriptor *sortDescriptor2 = [[[NSSortDescriptor alloc] initWithKey:sortString ascending:sortAsc] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor2, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
XLog(@"sortDescriptors: %@", sortDescriptors);
}
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
[...]
}