Ios5 CoreData openWithCompletionHandler在继续之前如何等待它完成

Ios5 CoreData openWithCompletionHandler在继续之前如何等待它完成,ios5,ios6,xcode4.5,Ios5,Ios6,Xcode4.5,我试图让CoreData正常工作,所以我自己做了一个小测试应用程序。除了一种类型的项目——openor save或closeWithCompletionHandler之外,所有项目都正常工作。我希望处理程序在其他事情发生之前完成。我不是把所有的代码都放在这里,而是把问题发生的地方放在这里。我已经尝试让这个WithCompletionHandler工作了相当长的一段时间,但我似乎不知道如何让代码的其余部分等待完成处理程序 -(void)viewDidLoad { [super viewDi

我试图让CoreData正常工作,所以我自己做了一个小测试应用程序。除了一种类型的项目——openor save或closeWithCompletionHandler之外,所有项目都正常工作。我希望处理程序在其他事情发生之前完成。我不是把所有的代码都放在这里,而是把问题发生的地方放在这里。我已经尝试让这个WithCompletionHandler工作了相当长的一段时间,但我似乎不知道如何让代码的其余部分等待完成处理程序

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self.contactsDatabase openWithCompletionHandler:^(BOOL success)
    {
        if (success)
            [self loadArrayFromFile];
    }
}

-(IBAction)deleteButton:(id)sender
{
    // I need this to NOT work until open is finished (or a previous save is finished)
    // delete an item in the database
    [self saveDatabase];
}

-(IBAction)addButton:(id)sender
{ 
    // I need this to NOT work until open is finished (or a previous save is finished)
    // add an item to the database
    [self saveDatabase];
}
在该设备上,如果连续10次单击“添加”或“删除”按钮,则会崩溃。另外,当它第一次加载时,您可以在加载数据库之前添加,这会造成错误