2014-03-26 52 views
0

你好,这里是我创建来处理我的UIManagedDocument在JIPManagedDocument.m代码:UIManagedDocument:传递给完成处理程序块不会被调用

+(JIPManagedDocument *)sharedManagedDocument 
{ 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
    NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 
    url = [url URLByAppendingPathComponent:@"DemoDocument"]; 
    _sharedManagedDocument = [[JIPManagedDocument alloc] initWithFileURL:url]; 
    }); 

    return _sharedManagedDocument; 
} 

-(void)performBlockWithDocument:(void (^)(JIPManagedDocument * managedDocument))block 
{ 
    void (^completionBlock) (BOOL) = ^(BOOL success) 
    { 
     if (success) 
     { 
      block(self); 
      NSLog(@"COULD PERFORM BLOCK WITH ManagedDocument"); 
     } 
     else 
     { 
      NSLog(@"COULDNT PERFORM BLOCK WITH ManagedDocument"); 
     } 
     self.openingDocument = NO; 
    }; 

    if (self.documentState == UIDocumentStateNormal) 
    { 
     completionBlock(YES); 
    } 

    else if (! self.openingDocument) 
    { 
     self.openingDocument = YES; 

     if (! [[NSFileManager defaultManager] fileExistsAtPath:[self.fileURL path]]) 
     { 
      [self  saveToURL:self.fileURL 
       forSaveOperation:UIDocumentSaveForCreating 
       completionHandler:completionBlock]; 
     } 


     else if (self.documentState == UIDocumentStateClosed) 
     { 
      [self openWithCompletionHandler:completionBlock]; 
     } 
    } 
} 

,然后当我尝试调用的方法是这样的:

[[JIPManagedDocument sharedManagedDocument] performBlockWithDocument:^(JIPManagedDocument *managedDocument) 
{ 
    //Do something 
}]; 

//Do something部分从未得到执行。

任何帮助将非常感激,非常感谢!

回答

0

作为参数传递的块,即将调用//执行某些操作的块。你只能在那里打电话:

if (success) 
{ 
    block(self); 
    NSLog(@"COULD PERFORM BLOCK WITH ManagedDocument"); 
} 

你确定这个条件满足了吗?

+0

那么在什么情况下,openwithcompletionhandler可能会失败? ------这是我在same.m文件中的单例方法:+(JIPManagedDocument *)sharedManagedDocument { static dispatch_once_t onceToken; dispatch_once(&onceToken,^ { NSURL * URL = [[[的NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; URL = [URL URLByAppendingPathComponent:@ “DemoDocument”]; _sharedManagedDocument = [[JIPManagedDocument的alloc] initWithFileURL :url]; }); return _sharedManagedDocument; } – Dontfearmistakes

相关问题