0

I am writing app that will Sync with address book and keep itself updated to addressbook.

When i am calling the syncing method or when its first launch and the app is copying all addressbook contact to the app data file, i want to show MBProgressHUD to the user.

I don't understand this well, i want the MBProgressHUD to show up on the call of this method, and to hide when its done.

- (void)syncingAddressbookWithCoreDataFile

Can you guide me how to use it in the way that i want?

I am confused with all the dispatch and the queues stuff because i am quite novice in all these things.

UPDATED

How can i make the progress of the indicator fill in as the task gets executed, i know there is a progress property in HUD (i am using MBProgressHUDModeDeterminate), but when i increase its value while my method is executing it doesn't change.. do i need to call something like redisplay?

Moody
  • 352
  • 3
  • 15
  • When you are calling the Sync method you should call [MBProgressHUD showHUDAddedTo:view animated:YES] and then when syncing is finished you should call [MBProgressHUD hideAllHUDsForView:keyWindow animated:animated]. Is that what you wanted to do? – Szu Jul 22 '14 at 12:28
  • Check this one: http://stackoverflow.com/questions/20139428/how-to-show-loading-view-controller-in-my-webservices/20139529#20139529 – Dhaval Bhadania Jul 22 '14 at 12:31

3 Answers3

3

With this code, you have the simpliest way to do what you want. It's not blocking the UI.

MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView: self.view];
[self.view addSubview: hud];
hud.labelText = @"Please wait...";

[hud showAnimated:YES whileExecutingBlock:^{
    [self syncingAddressbookWithCoreDataFile];
} completionBlock:^{
    // Put here code like reload table, refresh UI (...)
}];

But warning, as whileExecutingBlock using thread you have to make all UI change on main thread.

skrew
  • 879
  • 9
  • 16
  • Works like a charm, thank you. If i want to display completed indicator just after completion, do i create another HUD? or that would be a normal view? What if i want to make loading indicator (circle filling) while syncing, is that too much advanced? – Moody Jul 22 '14 at 13:37
  • Look in demos from MBProgressHud, there are all you want https://github.com/jdg/MBProgressHUD/tree/master/Demo – skrew Jul 22 '14 at 15:24
0
- (void)syncingAddressbookWithCoreDataFile { 

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

      //Your code goes here


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

}
Mika
  • 5,807
  • 6
  • 38
  • 83
0

Add this code where you want to show progress :

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

Now Add this code where you want to hide progress

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

Set your view where you want to display progress in : showHUDAddedTo && hideHUDForView

iBhavin
  • 1,261
  • 15
  • 30
  • I called `[MBProgressHUD showHUDAddedTo:self.view animated:YES];` before just before i call my sync method and hide after it.. It doesn't work. – Moody Jul 22 '14 at 13:20
  • You've to add MBProgressHUD to your view. – iBhavin Jul 23 '14 at 10:24