简体   繁体   English

NSFetchedResultsController-我的_sectionNameKeyPath_是_nil_! 为什么添加/删除时出现此错误?

[英]NSFetchedResultsController - My _sectionNameKeyPath_ is _nil_ !! Why am I getting this error when adding / deleting?

Classic case of the sections issue with NSFetchedResultsController and I am pulling my hair out. NSFetchedResultsController是本节中的典型案例,我正在拔头发。 I have set the sectionNameKeyPath to NIL which I've read is what you want for no sections (ie 1 section). 我已经将sectionNameKeyPath设置为NIL ,而我没有任何部分(即1个部分)想要读取的内容。

Code as follows: 代码如下:

- (NSFetchedResultsController *)fetchedResultsController {

    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription 
                                   entityForName:@"MyObjectType" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];

    NSSortDescriptor *sort = [[NSSortDescriptor alloc] 
                              initWithKey:@"name" ascending:NO];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

    [fetchRequest setFetchBatchSize:20];

    NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"accountExpenseTypeCache"];
    self.fetchedResultsController = theFetchedResultsController;
    _fetchedResultsController.delegate = self;

    [sort release];
    [fetchRequest release];
    [theFetchedResultsController release];


    return _fetchedResultsController;  
    }

As you can see my sectionNameKeyPath is set to nil and 如您所见,我的sectionNameKeyPath设置为nil,

Sometimes when I add or delete a row, it works. 有时,当我添加或删除行时,它会起作用。 Most often than not I get this serious crash in the console though when trying to delete or add: 通常,在尝试删除或添加时,我通常会在控制台中遇到严重崩溃:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView.m:955
(gdb) continue
2011-03-14 18:00:58.104 MyApplicationTest[5741:207] Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (3) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted). with userInfo (null)

What's the issue? 怎么了 I was reading the NSFetchedResultsController prior to 4.0 was built to handle User Driven updates? 我在读取4.0之前的NSFetchedResultsController旨在处理用户驱动的更新? I can only assume adding and deleting rows are considered User Driven updates? 我只能假定添加和删除行被视为用户驱动更新? Do I need to implement something like this? 我需要实现这样的东西吗?

How to implement re-ordering of CoreData records? 如何实现CoreData记录的重新排序?

?? ?? From what I've read though I don't understand why I have this issue when I have nil for sections. 从我所读的内容中,虽然我不明白为什么我在节中没有nil时会遇到这个问题。 Why is it saying that are 3 sections?! 为什么说是三个部分?

Thanks in advance! 提前致谢!

The number of sections in the tableview is not dependent on the sectionNameKeyPath of the fetched results controller but rather by the returned by the datasource's numberOfSectionsInTableView: . tableview中的节数不取决于获取的结果控制器的sectionNameKeyPath ,而是取决于数据源的numberOfSectionsInTableView:返回的值。

The error you are getting can be triggered by not sending the tableview a beginUpdate message prior to changing the data. 通过在更改数据之前不向tableview发送beginUpdate消息可以触发您遇到的错误。 The tableview may try to redraw itself while the count of the data is in flux. 当数据计数不断变化时,tableview可能会尝试重绘自身。

You must also implement the fetched results controller's delegate methods in the tableview's datasource object so that table is signaled when a change occurs. 您还必须在tableview的数据源对象中实现提取的结果控制器的委托方法,以便在发生更改时向表发出信号。

暂无
暂无

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

相关问题 为什么在加载TableViewcontroller时出现此错误 - Why am I getting this error when loading my TableViewcontroller 当我从其他应用程序向我的应用程序添加文件夹时出现错误,例如没有此类文件或目录 - when i am adding folder from other app to my app am getting error like no such file or directory 带有 NSFetchedResultsController 的 sectionNameKeyPath 不起作用 - sectionNameKeyPath with NSFetchedResultsController not working 使用NSFetchedResultsController和sectionNameKeyPath是关系时如何获取节名称? - How to fetch section name when using NSFetchedResultsController and sectionNameKeyPath is a relationship? 一个NSFetchedResultsController,日期为sectionNameKeyPath - A NSFetchedResultsController with date as sectionNameKeyPath 瞬态sectionNameKeyPath和NSSortDescriptor NSFetchedResultsController - Transient sectionNameKeyPath & NSSortDescriptor NSFetchedResultsController iOS /核心数据 - 如何更改NSFetchedResultsController的sectionNameKeyPath? - iOS / Core Data - How can I change sectionNameKeyPath of a NSFetchedResultsController? 为什么我要展示nil模态视图控制器? - why am I getting presenting nil modal view controller? iPhone-当视图映射正确时,为什么会出现此错误? - iPhone - Why am I getting this error when the view mapping is correct? 保存NSManagedObjectContext这个'干净'时为什么会出现合并错误? - Why am I getting a merge error when saving an NSManagedObjectContext this 'clean'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM