0

I use the following code to get the tap on image view and navigate to another view controller:

-(void)tapDetected:(UIGestureRecognizer *)recognizer{

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    NSLog(@"single Tap on imageview");

    ImageTapGesture *sender = (ImageTapGesture *)recognizer;

    UIStoryboard * storyboard = self.storyboard;

    tele * detail = [storyboard instantiateViewControllerWithIdentifier: @ "teledramaView"];

    detail.imagelink = sender.imageLink;

    detail.description = sender.description;

    detail.id = sender.id;

    [self.navigationController pushViewController: detail animated: YES];

    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

So far the code is working fine but the issue is the progress bar is not displaying properly.

It shows at the final moment before going to the other controller but the log comes before the progress bar: NSLog(@"single Tap on imageview");

Can anybody tell me why the progress bar is not working as it's meant to work? Thank you.

Robert
  • 5,278
  • 43
  • 65
  • 115
Kamal Upasena
  • 1,329
  • 4
  • 13
  • 38

1 Answers1

1

Well the answer is simple, since you are showing and hiding the the progressHUD in the same thread it will get removed as soon as it is added. Since you methods is executed on the main thread, which is also handeling any UI changes, your progressHUD will only be added after you method end. But since you remove the progressHUD on the last line it will also be removed directly. Even worse is that any code between adding and removing the HUD is blocking any UI changes.

You need to delay the loading a bit, to give the system time to present the progressHUD:

-(void)tapDetected:(UIGestureRecognizer *)recognizer{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];

NSLog(@"single Tap on imageview");

[self performSelector:@selector(navigateToDetailView:) withObject:recognizer afterDelay:0.0];

}

-(void) navigateToDetailView:(UIGestureRecognizer*)recognizer{
    ImageTapGesture *sender = (ImageTapGesture *)recognizer;

    UIStoryboard * storyboard = self.storyboard;

    tele * detail = [storyboard instantiateViewControllerWithIdentifier: @ "teledramaView"];
    detail.imagelink = sender.imageLink;
    detail.description = sender.description;
    detail.id = sender.id;

    [self.navigationController pushViewController: detail animated: YES];

    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
Kamal Upasena
  • 1,329
  • 4
  • 13
  • 38
rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • but it take soo much time to navigate to the other view controller soon after i tap the image view it sj=how me the log and after 5 - 8 seconds its move to the next one – Kamal Upasena Nov 20 '13 at 11:02
  • I've added an example how to make use iOS has time to display the progressHUD. – rckoenes Nov 20 '13 at 11:06
  • thank you very much but can you tell me how can i pass my `recognizer` object to the `navigateTodatailView` function – Kamal Upasena Nov 20 '13 at 11:08