我有一个名为GetInfoViewController的ViewController。基本上,它需要用户输入,然后将输入发送到NSObject类ServerConnection。 ServerConnection发出nsurlconnection请求,完成后我想要隐藏MBProgressHUD。
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
我不打算放入所有的nsurlconnection代码,因为我认为它并不适用..但如果你想要它我可以发布它
唯一重要的一点是: (在完成所有连接后调用。)
GetInfoViewController *getinfoVC = [[GetInfoViewController alloc]init];
[getinfoVC endProgressHUD];
我成功调用了getInfoViewController的endProgressHUD方法,因为它记录了“end called”。然而,进展情况仍在继续,并且不会隐藏。
任何输入都会有所帮助。
答案 0 :(得分:2)
显示HUD时尝试此方法。
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated;
这是MBProgressHUD的方法 - selector
应该是yelpConnectionMethod
并定位serverConnection
,对象= nil
,动画取决于你:)