Search code examples
iosobjective-cuikitmbprogresshud

Syncing MBProgressHUD Through Segue


This question may seem a little redundant in the forums, but I have not been able to come to a conclusion after a good deal of searching and I hope I will find my answer here.

I am having a problem using MBProgressHUD. I am using two view controllers. Controller A and Controller B.

I am also using a segue to transfer parsed data from A to B. I have tried putting the MBProgressHUD before the segue, but the progress bar doesn't show up until it reaches Controller B. I need to figure out a way to either thread it in the background or use it asynchronously.

Question: How do I have the MBProgressHUD load during the segue from Controller A to Controller B?

  1. Initiate Segue, and MBProgressHUD
  2. MBProgressHUD runs in background of Controller A while transferring parsed data to Controller B
  3. When it finally segues and reaches Controller B, MBProgressHUD stops.

For reference, this is an excerpt of my prepareForSegue method.

Thanks in advance.

    NSIndexPath *indexPath = [myTableView indexPathForSelectedRow];
    currentStore = [arrayOfStore objectAtIndex:indexPath.row];



    ReportsViewController *destinationVC = [segue destinationViewController];
    destinationVC.name = self.selectedCellName;
    destinationVC.startDate = selectedStartDate;
    destinationVC.endDate = selectedEndDate;
    destinationVC.netSales = currentStore.netSales;
    destinationVC.voids = currentStore.voids;
    destinationVC.discounts = currentStore.discounts;
    destinationVC.guestCount = currentStore.guestCount;
    destinationVC.peopleServed = currentStore.peopleServed;
    destinationVC.employeeClockIn = currentStore.employeesClock;

Solution

  • This worked perfect for me. I just dispatched the segue and threw the MBProgressHUD afterwards.

    dispatch_queue_t queue = dispatch_queue_create("Camaleon Reports", NULL);
            dispatch_async(queue, ^{
                dispatch_async(dispatch_get_main_queue(), ^{
    
                    [self performSegueWithIdentifier:@"report" sender:nil];
    
                });
            });
    
    [self loadingData];