是否無法獲得完成塊成功,然後從另一個方法接收數據?如何從objective-c中的另一個方法執行完成塊?
@property myCompletion;
// I have first call listeners, i can't add this in to "createOrderWithsuccess"
-(void)listeners {
[[SocketIOManager sharedInstance].socket on:@"someAction" callback:^(NSArray* data, SocketAckEmitter* ack) {
// data received
myCompletion(data);
}];
}
// this will be called <del>first</del> later
- (void)createOrderWithsuccess:^(NSArray *data) {
// but it has to wait then data will be received
myCompletion = success;
}
不要開玩笑。我在這行上有'ERROR ** EXC_BAD_ACCESS(code = 1,address = 0xc)**'_myCompletion(data);' –
你是不是先調用'createOrderWithSuccess:'?你可以在if語句中調用'_myCompletion(data)':if(_myCompletion)_myCompletion(data)'。 – Joakim
謝謝,它的工作:)我需要添加'if(_myCompletion)_myCompletion(data)_myCompletion = nil;'?根據hanh answer.With'_myCompletion = nil'它只會工作一次。我無法設置_myCompletion = nil,因爲監聽器會多次調用。 –