문제

I have a ViewController called GetInfoViewController. Basically it takes the users input and then sends the input to a NSObject class, ServerConnection. ServerConnection makes a nsurlconnection request and when it is done I want the MBProgressHUD to hide.

GetInfoViewController

    - (IBAction)go:(id)sender{

    ServerConnection *serverConnection = [[ServerConnection alloc]init];

    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = @"Searching...";

// here the progressHUD shows normally, and the yelpConnectionMethod is successful in retrieving the result.

    [serverConnection yelpConnectionMethod];


}


-(void)endProgressHUD{
    NSLog(@"end called");


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

ServerConnection.h

I am not going to put all the nsurlconnection code because I don't think it really applies.. but if you want it I can post it

The only line that matters is: (this is called after all the connections are done.)

GetInfoViewController *getinfoVC = [[GetInfoViewController alloc]init];
[getinfoVC endProgressHUD];

I call the endProgressHUD method of the getInfoViewController successfully, as it logs "end called". however, the progress hud stays spinning and does not hide.

Any input would be helpful.

도움이 되었습니까?

해결책

Try this method when showing the HUD.

- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated;

It is a method of MBProgressHUD - selector should be the yelpConnectionMethod and target the serverConnection, object = nil and animated depends on you :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top