【问题标题】:NSFetchedResultsController performFetch doesn't workNSFetchedResultsController performFetch 不起作用
【发布时间】:2015-10-02 08:00:52
【问题描述】:

我在屏幕上进行了分段控制。第一个分段项目用于广告(广告表),第二个分段项目用于订单(订单表)。 每次当用户选择分段项时,我都会重新创建 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 and cellForRowAtIndexPath 未被调用)。因此,当我调用fetchedResultsController!.performFetch()时,第二次 NSFetchResultController 的新实例(与核心数据中的第二个表相关)没有做任何事情

【问题讨论】:

    标签: ios uitableview core-data nsfetchedresultscontroller nsfetchrequest


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      相关资源
      最近更新 更多