Ios UITableView赢得';t在iCloud同步后重新加载(Swift 2)

Ios UITableView赢得';t在iCloud同步后重新加载(Swift 2),ios,swift,uitableview,core-data,icloud,Ios,Swift,Uitableview,Core Data,Icloud,我有一个通过iCloud同步核心数据的应用程序。同步工作正常,但我在其中显示数据的tableView(在名为“ResultsView”的视图中)在iCloud同步后不会重新加载;我需要转到另一个视图并返回我的ResultsView以查看更改 这是我处理核心数据同步的方式(在AppDelegate.swift中): 同样在AppDelegate中,要通过iCloud处理更新,请执行以下操作: // MARK: - iCloud // This handles the updates to the

我有一个通过iCloud同步核心数据的应用程序。同步工作正常,但我在其中显示数据的tableView(在名为“ResultsView”的视图中)在iCloud同步后不会重新加载;我需要转到另一个视图并返回我的ResultsView以查看更改

这是我处理核心数据同步的方式(在AppDelegate.swift中):

同样在AppDelegate中,要通过iCloud处理更新,请执行以下操作:

// MARK: - iCloud
// This handles the updates to the data via iCLoud updates

func registerCoordinatorForStoreNotifications (coordinator : NSPersistentStoreCoordinator) {
    let nc : NSNotificationCenter = NSNotificationCenter.defaultCenter();

    nc.addObserver(self, selector: "handleStoresWillChange:",
        name: NSPersistentStoreCoordinatorStoresWillChangeNotification,
        object: coordinator)

    nc.addObserver(self, selector: "handleStoresDidChange:",
        name: NSPersistentStoreCoordinatorStoresDidChangeNotification,
        object: coordinator)

    nc.addObserver(self, selector: "handleStoresWillRemove:",
        name: NSPersistentStoreCoordinatorWillRemoveStoreNotification,
        object: coordinator)

    nc.addObserver(self, selector: "handleStoreChangedUbiquitousContent:",
        name: NSPersistentStoreDidImportUbiquitousContentChangesNotification,
        object: coordinator)
}
我在ResultsView的ViewWillDisplay方法中获取核心数据,并在ViewWillDisplay和ViewDidDisplay中获取
self.tableView.reloadData()

我错过了什么


提前感谢

[编辑-未正确阅读问题!]

如果您的数据可以在视图打开时更改(这可能是因为iCloud同步是异步的):您的视图需要知道它所基于的数据已更改,因此在同步CoreData后,请调用它。另见


如果您的数据在视图打开时无法更改,则会出现“视图中”,请确保在调用super之前数据已完全同步。请注意,与iCloud同步将是异步的,因此仅调用sync方法是不够的。当视图如上所述打开时,可以更容易地假设它将更改。

感谢您的回答。抱歉再次询问,我应该在哪里调用
setNeedsDisplay
?我在
viewDidLoad
和函数跟踪
nspersistentstoredidimportubiquitiouscontentchangesnotification
中都尝试过,但都不起作用。我需要转到另一个视图并再次输入我的视图以查看更改。谢谢again@CarlosBF在viewDidLoad中不需要它-系统将在视图首次出现时绘制视图。我不确定我是否能够进一步帮助确定何时触发setNeedsDisplay-CoreData对于本地数据非常有用,但对于iCloud同步来说却非常复杂,因此在经历了很多挫折之后,我转而使用CloudKit。另外一个问题可能值得一提,那就是让“CoreData with iCloud”专家告诉您从哪个通知触发视图重画。
// MARK: - iCloud
// This handles the updates to the data via iCLoud updates

func registerCoordinatorForStoreNotifications (coordinator : NSPersistentStoreCoordinator) {
    let nc : NSNotificationCenter = NSNotificationCenter.defaultCenter();

    nc.addObserver(self, selector: "handleStoresWillChange:",
        name: NSPersistentStoreCoordinatorStoresWillChangeNotification,
        object: coordinator)

    nc.addObserver(self, selector: "handleStoresDidChange:",
        name: NSPersistentStoreCoordinatorStoresDidChangeNotification,
        object: coordinator)

    nc.addObserver(self, selector: "handleStoresWillRemove:",
        name: NSPersistentStoreCoordinatorWillRemoveStoreNotification,
        object: coordinator)

    nc.addObserver(self, selector: "handleStoreChangedUbiquitousContent:",
        name: NSPersistentStoreDidImportUbiquitousContentChangesNotification,
        object: coordinator)
}