我必须在视图中调用三个Web服务。我正在使用ASIHttprequest
电话。我将一个接一个地调用每个Web服务。它会导致崩溃
-[INetServices respondsToSelector:]: message sent to deallocated instance 0x12629a10
我如何克服这个错误的请求错误。
HUDadmin = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUDadmin];
HUDadmin.delegate = self;
HUDadmin.labelText =@"Loading";
//[HUD hide:YES afterDelay:20];
[HUDadmin showWhileExecuting:@selector(adminCheck) onTarget:self withObject:nil animated:YES];
其中adminCheck
如下:
-(void)adminCheck
{
INetServices *inetadmin=[[INetServices alloc]init];
NSString *response = [inetadmin doHTTPPostadmincheck:getUserId comm_id:str_commId];
if (!response) {
NSLog(@"response nil ");
return;
}
NSMutableArray *jsonarrayResponse=[response JSONValue];
NSLog(@"Admin:%@",jsonarrayResponse);
str_adminStatus = [jsonarrayResponse valueForKey:@"admin_status"];
if ([[jsonarrayResponse valueForKey:@"status"] isEqualToString:@"success"]==TRUE)
{
if ([[jsonarrayResponse valueForKey:@"message"]isEqualToString:@"Admin user!."]==TRUE)
{
int_adminStatus=1;
}
else
{
int_adminStatus=0;
}
}
[self performSelectorOnMainThread:@selector(hideProgress) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(CommunityDetailwebservice)
withObject:nil waitUntilDone:NO];
}
答案 0 :(得分:0)
根据到目前为止提供的内容,很难准确确定僵尸的来源是什么。 exception breakpoint或堆栈跟踪可能会缩小范围。
话虽如此,我发现在调用showWhileExecuting
时对其他方法的异步调用有点令人担忧,特别是因为hideProgress
试图隐藏您当前正在显示的HUD。
我倾向于重构此代码,并将HUD传递给选择器,以便运行所有三种Web服务:
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:hud];
[hud showWhileExecuting:@selector(performWebServiceRequests:) onTarget:self withObject:hud animated:YES];
这样,performWebServiceRequests:
更新HUD并执行各种同步Web服务请求:
- (void)performNetworkRequests:(MBProgressHUD *)hud
{
hud.labelText = @"step 1";
[self adminCheck];
hud.labelText = @"step 2";
[self communityDetailWebService];
hud.labelText = @"step 3";
[self thirdWebService];
}
如果您需要调用后一个Web服务取决于之前的Web服务是否成功,您可以相应地调整performWebServiceRequests
。例如,如果这三个Web服务方法在成功时返回TRUE
,或者在失败时返回FALSE
,则可以执行以下操作:
- (void)performNetworkRequests:(MBProgressHUD *)hud
{
hud.labelText = @"step 1";
if (![self adminCheck])
return;
hud.labelText = @"step 2";
if (![self communityDetailWebService])
return;
hud.labelText = @"step 3";
[self thirdWebService];
}
无论如何,当您从performWebServiceRequests
方法返回时,HUD将自动被解雇。