iosobjective-cmethodssvprogresshud

Method code not executing in the correct order


I have two methods. One method is used to load my SVProgressHUD, the second method is used to get data from my coreData and sort it then present it in a new UITableView. The user selects are UITableViewCell which calls:

didSelectRowAtIndexPath

Then I have two method calls in this, the first is:

[self loadHUD];

This method loads a hud (which never shows if I implement the second method in didSelectRowAtIndexPath). This is the second method:

[self loadAndSortArray];

When I call this for some reason it is preventing the SVProgressHud from ever appearing, however if I remove this method call then the hud loads fine.

I would like to know how I can have both methods but display the hud before the second method starts ?


Solution

  • All the views are refreshed in the main thread, if you don't put expensive process like loadAndSortArray in background thread this happen to you.

    You can put that method inside:

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
        [self loadAndSortArray];
    });