我非常有MBProgressHUD和NSURLConnection的挣扎......MBProgressHUD] NSURLConnection的以异步方式
我使用showWhileExecuting方法调用具有内部NSURLConnection的代码另一个私有方法。
-(void)HUD
{
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Initializing";
[HUD showWhileExecuting:@selector(authenticateWithPhoneNumber) onTarget:self withObject:nil animated:YES];
}
这是我通过showWhileExecuting方法调用的方法。
-(void)authenticateWithPhoneNumber
{
// Do some stuff
// Get JSON data using NSURLConnection HERE
if(successful)
{
//EXC_BAD_ACCESS error here
[self performSegueWithIdentifier:@"A" sender:self];
}
else
{
//EXC_BAD_ACCESS error here
[self performSegueWithIdentifier:@"B" sender:self];
}
}
当运行该应用程序,我得到EXC_BAD_ACCESS错误以及以下消息:
28 0x344c0b8b 29 0x344c082b 30 0xf2d39 - [AuthenticationConfirmationViewController authenticateWithPhoneNumber] 31 0xd9013 - [MBProgressHUD launchExecution]
假设那些执行segue代码是问题...我把它们移到HUD方法里面就像这样...
-(void)HUD
{
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Initializing";
[HUD showWhileExecuting:@selector(authenticateWithPhoneNumber) onTarget:self withObject:nil animated:YES];
if(successful)
{
[self performSegueWithIdentifier:@"A" sender:self];
}
else
{
[self performSegueWithIdentifier:@"B" sender:self];
}
}
现在移动到下一个页面是好的......但它跳到甚至JSON数据处理过程之前的某个网页上。
导致所有这些麻烦的问题是什么? 在这种情况下,解决问题的正确方法是什么?在progress.m
在哪里你从视图中删除hud? –
嗯,我使用ARC,并假设我不需要释放它...我必须? – Raccoon
'showWhileExecuting'中有两行保留hud,你是否必须使用'showWhileExecuting'你不能在hud内部使用另一种方法,比如'showHUDAddedTo'? –