繁体   English   中英

NSFetchedResultsController无法将对象正确插入UITableView

[英]NSFetchedResultsController not inserting objects into UITableView correctly

我正在使用带有NSFetchedResultsController的UITableView。 提取具有一些谓词,并且一切正常。 所有对象都有一个索引,应以此索引对它们进行排序。 当我插入一个对象时,该索引的设置正确,但是有时该对象出现在错误的索引路径中。 但是,当我离开视图控制器并返回时,顺序是正确的。 我尝试刷新controllerDidChangeContent:的表视图,但没有任何效果。

这是我的提取请求:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"NoteContent" inManagedObjectContext:self.managedObjectContext];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"note IN %@", self.container.notes];
    [fetchRequest setPredicate:predicate];
    [fetchRequest setEntity:entity];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort key as appropriate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"note.creation.description" ascending:NO];
    NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES];
    NSArray *sortDescriptors = @[sortDescriptor, sortDescriptor2];
    [fetchRequest setSortDescriptors:sortDescriptors];

感谢您对可能出现的问题有任何想法。

原来插入部分是完全可以的,但是删除时我没有更新索引,这导致了索引空白。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM