0

我已經在屏幕上分段控制。 1個分段項目用於廣告(廣告表格),第二個分段項目用於訂單(訂單表格)。 當用戶選擇所分割的項每一次,我重新NSFetchResultController的新實例讀取請求到另一個數據表(但UI我總是隻有一個的UITableView self.tableViewMain):NSFetchedResultsController performFetch不起作用

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()

回答

1

時,NSFetchResultController的新實例(與核心數據中的第二個表有關)不會執行任何操作。您應該調用tableViewMain.reloadData()以獲取表來重新加載自身。

相關問題