2014-09-05 102 views
1

我是仙女新的目標C和我有以下困境。在類預測中的方法結束運行後,我想要一段代碼運行。客觀C阻止代碼

-(void)populate: (void (^)())completionHandler{//method that should run first 
    //code that runs first 
} 

我打電話的主要功能

[prediction populate:^{ 
    NSLog(@"it works")//it works is new displayed 
}]; 

這個方法我想到「它的工作原理」要顯示的填入方法運行結束之後。但是這並沒有發生。我究竟做錯了什麼?

回答

5

只需將completionHandler參數添加到您的方法中就不會自動運行它。當您完成populate:方法中需要做的任何事情時,您需要自己調用它:

-(void)populate: (void (^)())completionHandler { //method that should run first 
    //code that runs first 

    if (completionHandler) { 
     completionHandler(); 
    } 
}