我正在使用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