我正在使用SOAP WebService,並使用for循環來循環接收的帳戶。如何停止for循環並執行另一個方法,然後返回以繼續使用objective-c?
在每一個循環中,我調用WebService的另一個請求,所以我需要的是在發出請求時在for循環中,去獲取響應,然後繼續循環。
下面是for循環的代碼:
for (A2AWCAccount* account in accountList.Accounts) {
[_internalAccounts addObject:[[AccountDO alloc] initWithAccountName:[account localizedDescription] AccountNumber:account.Number Balance:[account.CurBal doubleValue] Currency:account.Curr]];
DataBank* dataBank = [DataBank getInstace];
A2AService* service = [A2AService service];
service.logging = YES;
A2AWCListCard* accountList = [A2AWCListCard alloc];
accountList.CustMnemonic = dataBank.customerId;
accountList.SessionID = dataBank.sessionId;
accountList.AccountNumber = account.Number;
accountList.Type = @"V";
// here i make the request
[service wrListCard:self listCard:accountList];
}
這裏是該得到的迴應
- (void) onload:(id)value {
if ([value isKindOfClass:[A2AWCListCard class]]) {
A2AWCListCard* obj = (A2AWCListCard*) value;
if (obj.ErrorCode != 0) {
if (obj.ErrorCode == 109) {
[self handleSessionError];
return;
}else if (obj.ErrorCode == 116)
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Info", @"Info") message:[obj localizedError] delegate:self cancelButtonTitle:NSLocalizedString(@"Ok", @"Ok") otherButtonTitles:nil, nil];
alert.tag = 5;
[alert show];
return;
}
[self handleRequestError:[obj localizedError] closeView:YES];
return;
}
for (A2AWCCard* account in obj.Cards) {
[_cards addObject:[[CardDO alloc] initWithCardNumber:account.CardNo balance:[account.CurBal doubleValue] minimumPayment:account.CardAcc currencyCode:account.Status status:account.Curr cardName:[account localizedDescription] cardNo:account.Number]];
_totalBalance += [account.CurBal doubleValue];
}
[cardsPicker setNeedsDisplay];
[cardsPicker reloadAllComponents];
_servicesInitialized = YES;
}
}
的問題發生在這裏的是,循環使其調用該方法的代碼N次取決於帳戶的數量,例如如果有3個帳戶,它會發出3次請求,然後我等待3次響應,所以它有助於彼此,有時是因爲服務器有點慢。
請幫助嗎?
這些調用是在主線程上執行的嗎? – trojanfoe
我不知道,但我認爲是它的主線程,因爲它沒有設置爲任何其他線程 –
不會阻止主(UI)線程很長一段時間? '[服務wrListCard:self listCard:accountList];'如何實現? – trojanfoe