如何在clearCoreDataStore()之后更新视图?

时间:2017-04-12 21:17:41

标签: ios swift xcode

我有一个调用clearCoreDataStore()的按钮。但是,在执行后视图不会更新,它仍会显示内容。我该如何更新?

在相关说明中,如何在中将数据插入到应用的核心数据堆栈后更新视图

我在类声明之外有以下'抓取'代码:

fileprivate var fetchedResultsControllerForMapEntity: 
NSFetchedResultsController<Map> = {
// Create Fetch Request
let fetchRequest: NSFetchRequest<Map> = Map.fetchRequest()

// Configure Fetch Request
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]

// Create Fetched Results Controller
let fetchedResultsControllerForMapEntity = 
NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)

return fetchedResultsControllerForMapEntity
}()

fileprivate var fetchedResultsControllerForCoordinateEntity: NSFetchedResultsController<Coordinate> = {
// Create Fetch Request
let fetchRequest: NSFetchRequest<Coordinate> = Coordinate.fetchRequest()

// Configure Fetch Request
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "latitude", ascending: true)]
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "longitude", ascending: true)]

// Create Fetched Results Controller
let fetchedResultsControllerForCoordinateEntity = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)

return fetchedResultsControllerForCoordinateEntity
}()

在viewDidLoad上,我这样做:

do {
        try fetchedResultsControllerForMapEntity.performFetch()
        try fetchedResultsControllerForCoordinateEntity.performFetch()
} catch 

0 个答案:

没有答案