iosuitableviewuiactivityindicatorviewsvprogresshud

SVProgressHUD how to show in next ViewController


I am having a TableViewController with some items and then having a filterViewController, where filter data in TableViewController according to the values. It is made with using UISwitch. Anyway, I would like to ask, how to add a SVProgressHUD to the action, when I return back from filterViewController with filtered Array. It takes some secs to filter and display them in tableView. I already tried dispatch_async and it doesn't even display HUD. I have an IBAction for button in filterViewController to confirm values and send them to TableViewController.

If I added HUD to the action in filterViewController, HUD doesn't display in TableViewController.

filterViewController.m

-(IBAction)Done:(id)sender{

    [self willMoveToParentViewController:nil];

    [self.navigationController popViewControllerAnimated:YES];


}

TableViewController.m

- (void)filterController:(filterViewController *)controller didEditConfig:(NSMutableDictionary *)config
{
    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeGradient];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // time-consuming task

        self.konfigg = config;


        NSSet *filter = [config keysOfEntriesPassingTest:
                         ^BOOL (id key, NSNumber *value, BOOL *stop) {
                             return [value boolValue];

                         }];

        NSLog(@"filtered keys: %@ (%lu of %lu)", filter, (unsigned long)filter.count, (unsigned long)config.count);

        PFQuery *query = [PFQuery queryWithClassName:@"Class"];
        [query addDescendingOrder:@"createdAt"];
        [query whereKey:@"eventDay" containedIn:[filter allObjects]];

        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

            if (!error) {
                self.itemss = [objects mutableCopy];
                [self.MainTable reloadData];

                NSLog(@"Got filtered results %@ (%lu)", objects, (unsigned long)objects.count);
            }}
         ];
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
    });

}

Solution

  • Got it. Made just BOOL for the filter in TableViewController. It was easier than I thought.