UIDocumentStateChangedNotification检测删除项

时间:2013-10-11 17:20:09

标签: ios objective-c icloud uidocument

我想知道是否可以使用UIDocumentStateChangedNotification检测项是否被删除,如果没有,我如何检测项是否从云中删除?

1 个答案:

答案 0 :(得分:0)

将UIDocumentStateChangedNotification的观察者添加到viewDidLoad。

[[NSNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(itemHasChanged:)
        name:UIDocumentStateChangedNotification
        object:nil];

如果更改对象的documentState设置为UIDocumentStateSavingError,则删除它。

-(void) itemHasChanged:(id)sender {
    UIDocument *itemDoc = [sender object]; 

    if ([itemDoc documentState] == UIDocumentStateSavingError) {
      // your code to handle a deleted document goes here
      // in my case I remove that object from my array of current objects.
    }
}