我有一个名为GetInfoViewController的ViewController。基本上,它接受用户的输入,然后将输入发送到NSObject类ServerConnection。ServerConnection发出nsurlronnection请求,完成后我希望MBProgressHUD隐藏起来。
GetInfoView控制器
- (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
我不会把所有的nsurconnection代码都放进去,因为我不认为它真的适用。。但如果你想要,我可以把它贴在上
唯一重要的一句话是:(这是在完成所有连接后调用的。)
GetInfoViewController *getinfoVC = [[GetInfoViewController alloc]init];
[getinfoVC endProgressHUD];
我成功地调用了getInfoViewController的endProgressHUD方法,因为它记录了"endcalled"。然而,进步的hud保持旋转,并没有隐藏。
任何意见都会有所帮助。
在显示HUD时尝试此方法。
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated;
这是MBProgressHUD的一种方法-selector
应该是yelpConnectionMethod
,目标是serverConnection
,object=nil
,动画取决于您:)