Reputation: 1427
I'm badly struggling with MBProgressHUD and NSURLconnection...
I'm using showWhileExecuting method to call another private method that has NSURLConnection codes inside.
-(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];
}
and this is the method I'm calling via showWhileExecuting method.
-(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];
}
}
When I run the app, I get that EXC_BAD_ACCESS error as well as the following message:
28 0x344c0b8b 29 0x344c082b 30 0xf2d39 -[AuthenticationConfirmationViewController authenticateWithPhoneNumber] 31 0xd9013 -[MBProgressHUD launchExecution]
Assuming that those perform segue codes are the problem... I moved them to inside of the HUD method something like this...
-(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];
}
}
Now moving to the next page is fine... EXCEPT that it jumps to one of the pages even before JSON data handling procedure is over.
What's the problem causing all these troubles? What's the right way to approach to the problem in this situation?
Upvotes: 1
Views: 1060
Reputation: 4914
Well original method in progress.m has to do something with threading and I am not fun of something I do not completely understand
#pragma mark - Threading
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {
methodForExecution = method;
targetForExecution = MB_RETAIN(target);
objectForExecution = MB_RETAIN(object);
// Launch execution in new thread
self.taskInProgress = YES;
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil];
// Show HUD view
[self show:animated];
}
I suggest you to use showHUDAddedTo
-(void)authenticateWithPhoneNumber
{
// Do some stuff
// Add right before your JSON executions
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Initializing...";
// Get JSON data using NSURLConnection HERE
if(successful)
{
// Add at start of requestFinished AND requestFailed basically remove hud just before your segues
[MBProgressHUD hideHUDForView:self.view animated:YES];
//EXC_BAD_ACCESS error here
[self performSegueWithIdentifier:@"A" sender:self];
}
else
{
// Add at start of requestFinished AND requestFailed basically remove hud just before your segues
[MBProgressHUD hideHUDForView:self.view animated:YES];
//EXC_BAD_ACCESS error here
[self performSegueWithIdentifier:@"B" sender:self];
}
}
Upvotes: 1