- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在我的 View Controller 中,我有一个已实现的 fetchedResultsController 并且一切正常(显示行、多个部分、获取等)。
但是当我尝试更新或删除部分中的最后一行时出现错误(当我说“最后一行”时,我的意思是该部分中只剩下一行)。如果该部分中有不止一行,当我更新它的值(在 Core Data 中)时,它不会发生任何错误。我读过 this , this和 this但它对我没有帮助(解决方案已过时),而且我还没有在 StackOverflow 和互联网上找到任何解决我的问题的方法。我需要帮助。我正在使用 Xcode 8.3.3 和 Swift 3。
这是我在尝试更新 tableView 的任何部分中的“唯一”行时遇到的错误:
CoreData: error: Serious application error.
An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.
UITableView internal bug: unable to generate a new section map with old section count:
1 and new section count: 0 with userInfo (null)
我正在使用此方法返回节数:
func numberOfSections(in tableView: UITableView) -> Int {
return fetchedResultsController?.sections?.count ?? 0
}
这是获取行数的方法:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let sections = fetchedResultsController.sections {
let currentSection = sections[section]
return currentSection.numberOfObjects
}
return 0
}
我的 View Controller 中还有以下方法:
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
self.tableView.beginUpdates()
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
self.tableView.endUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
case .delete:
guard let path = indexPath
else { return }
tableView.deleteRows(at: [path],
with: .none)
case .insert:
guard let path = newIndexPath
else { return }
tableView.insertRows(at: [path],
with: .automatic)
case .move:
guard let _ = indexPath,
let _ = newIndexPath
else { return }
if indexPath != newIndexPath {
tableView.deleteRows(at: [indexPath!], with: .none)
tableView.insertRows(at: [newIndexPath!], with: .none)
}
case .update:
guard let path = indexPath
else { return }
tableView.reloadRows(at: [path], with: .none) // No blinking with .none
}
}
如果没有部分,我尝试更改 numberOfSections 方法以返回 1 个部分,
func numberOfSections(in tableView: UITableView) -> Int {
if self.fetchedResultsController.sections?.count == 0 {
return 1
} else {
return fetchedResultsController?.sections?.count ?? 1
}
但在这种情况下我遇到了另一个错误。
An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.
*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray with userInfo (null)
最佳答案
经过一些尝试,我找到了解决方案:
添加此方法后我没有错误:
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
switch type {
case .insert:
tableView.insertSections(NSIndexSet(index: sectionIndex) as IndexSet, with: .fade)
case .delete:
tableView.deleteSections(NSIndexSet(index: sectionIndex) as IndexSet, with: .fade)
case .move:
break
case .update:
break
}
}
关于ios - 无法生成具有旧节数 : 1 and new section count: 0 with FetchedResultsController 的新节图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45736960/
这个问题在这里已经有了答案: Multi level categories with items on all levels in UITableView (1 个回答) 关闭 6 年前。 标题说明
我想在编译时从代码中删除未使用的函数。然后我写一些代码(main.c): #include const char *get1(); int main() { puts( get1() );
升级到 Xcode 4.4 后,当我尝试在 iPhone 或 iPad 上运行我的(通用)应用程序时,我遇到了这个烦人的链接器错误。如果我在 iOS 模拟器上运行它,我没有问题... 我尝试添加 ar
我以前从未见过这个错误,我搜索了它可能发生的原因,但找不到任何相关信息: CoreData: error: Serious application error. An exception was ca
我正在使用以下内容填充 UITableView 部分的各个部分: fetchedResultsController = NSFetchedResultsController(fetchReques
是标签允许包含在另一个 中标签?它会在 HTML5 中验证吗? 最佳答案 Yes ! w3 鼓励您在分节内容的元素中显式包装节,而不是依赖于在分节内容的一个元素中包含多个标题而生成的隐式节,并且允许
我使用部分来确定页面的不同部分。这些部分的底部边距为 90px,但是当在页面中创建/放置 ID 为“clients-full”的部分时,我希望出现在它之前/上方的任何部分的底部边距为 0。我可以做吗这
我现在有一个第三方提供的c静态库(用arm-gcc编译的)。我不可能(让第三方)重新编译库。 在调查库内容时,我发现 gcc 选项 -ffunction-sections 和 -fdata-secti
大家好,我陷入了一个奇怪的问题,我正在重新加载 tableViewSection,它正在正确地重新加载该部分,但它隐藏了其他部分,直到我向上或向下滚动它。我使用以下代码重新加载 func tabl
在我的项目中,我有扩展 ArrayAdapter 的类并实现 SectionIndexer .实现方法时getPositionForSection和 getSectionForPosition我发现了
我正在尝试编译 scss,以便在它具有 class1 时获得该部分。我不知道如何去做,因为我得到了空间,而且它的工作方式不一样。 当前输出: .class2 > section .class1 {
我正在阅读 Mark Pilgirm 的“Dive into HTML5”和 semantics section ,它讨论了 HTML5 如何引入 和 元素。它说 s 代表通用文档或部分,而 s
我是使用ARM编译器进行Keil Microvision V5.12编程的新手。 我无法编译一个简单的组装项目,但出现此错误: .\Objects\learn.sct(7): error: L6236
这是我第一次在这里问问题,但我不得不说这个网站在过去几个月里给了我巨大的帮助(iphone-dev-wise),我为此表示感谢。 但是,我没有找到解决这个问题的方法:我有一个包含 2 个部分的 UIT
我在 IOS 中实现了一个 TableView (4 个部分)。问题是我刚刚在第一部分添加了一个部分标题。其他部分没有标题。第一部分没有行(行数为 0)。其他部分有多行。当我滚动时,第一部分的标题不粘
我有一个包含多个部分的表格 View 。我希望能够将行从一个部分移动到另一个部分,并在没有行时删除一个部分。我正在尝试通过 moveRowAtIndexPath 执行此操作,但我的代码不起作用并抛出
我正在尝试删除不符合 for 循环条件的行。但是,我收到错误消息:“尝试从第 1 部分删除第 0 行,但更新前只有 1 个部分。”我以前从未见过这个,也不确定为什么会收到它。 我的代码: func
GCC 页面中针对功能部分和数据部分选项的以下内容: -ffunction-sections -fdata-sections Place each function or data item into
我想在安装新数据库之前删除旧数据库,以便为用户更新它。 我有以下情况: 在我的 Components 部分中,我为用户提供了一个选项: [Components] Name: "updateDataba
我从工作区添加了一个测试用例。可能已经一周了,所以我不记得它是来自 Backlog 还是来自董事会。 现在,当我进入测试/测试计划时,它没有出现。我找不到将其添加到测试套件的方法。 我可以通过测试区域
我是一名优秀的程序员,十分优秀!