gpt4 book ai didi

ios - NSFetchedResultsController performFetch 不起作用

转载 作者:行者123 更新时间:2023-11-29 01:36:34 25 4
gpt4 key购买 nike

我在屏幕上有分段控制。 1 个分段项目用于广告(广告表),第二个分段项目用于订单(订单表)。每次当用户选择分段项目时,我都会重新创建 NSFetchResultController 的实例,并向另一个数据表发出新的获取请求(但在 UI 上我总是只有一个 UITableView self.tableViewMain):

let entityName = screen == ProfileScreen.Ads ? kDB_entity_DBAd : kDB_entity_DBOrder
let entityDescription = NSEntityDescription.entityForName(entityName, inManagedObjectContext: (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext)
let fetchRequest = NSFetchRequest()
fetchRequest.entity = entityDescription
self.fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: (UIApplication.sharedApplication().delegate! as! AppDelegate).managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
do {
try fetchedResultsController!.performFetch()
} catch {
print("An error occurred in fetchresultcontroller")
}

但第一次它正确地重新加载数据,但第二次 fetchresultcontroller 甚至不重新加载表(numberOfRowsInSection 和 cellForRowAtIndexPath 未被调用)。因此,当我调用 fetchedResultsController!.performFetch()

时,第二次 NSFetchResultController 的新实例(与核心数据中的第二个表相关)没有做任何事情

最佳答案

您应该调用 tableViewMain.reloadData() 让表格自行重新加载。

关于ios - NSFetchedResultsController performFetch 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32902858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com