-(void)method1
{
[self method2];
[self method3]; //After finishing execution of method2 and its delegates I want to execute method3
}
這裏method2在它調用時運行,但在它的委託方法執行之前,方法3開始執行。如何避免這種情況?任何建議或代碼,請等待委託方法在ios中完成執行
我叫方法2
-(void)method2
{
....
connection= [[NSURLConnection alloc] initWithRequest:req delegate:self ];
....
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data
{
}
..
..
+1這個,如果你能定位到iOS 5及更高版本。只要注意''completionHandler'塊在後臺線程/隊列上被調用。 –
@SteveWilford - 檢查我更新的ans,在完成塊中,添加一個塊來調用主線程的方法。就像解析完成後,UI更新需要之後,就可以使用這種方法。 – Mrunal