有时MBProgressHUD不显示

时间:2012-09-03 04:16:59

标签: iphone ios ios4 mbprogresshud

我有uitableview中显示的歌曲标题列表以及“购买”按钮。当点击该按钮时,我正在显示MBProgressHUD。但有时它没有显示。否则它会禁用用户交互,因为它在下面代码。

但为什么有时候不显示MBProgressHUD?

请让我知道,非常感谢。

  

以下是代码

-(void) buySong:(UIButton *)button
    {
      self.view.userInteractionEnabled = NO;

      self.navigationController.navigationBar.userInteractionEnabled = NO;

      MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
      hud.labelText = @"Proessing...";
      hud.yOffset = -80;

      UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
      NSIndexPath *indexPath = [[self tblViewChildrenPoems] indexPathForCell:cell];

      PSSongTags *songTags = [self.songsArray objectAtIndex:indexPath.row];
      [ [PurchaseViewController sharedPurchaseManager] startPurchase:songTags];

    }

1 个答案:

答案 0 :(得分:2)

试试这段代码可能对你有帮助......

在您的.h文件中导入。

 #import "MBProgressHUD.h"

设置委托。

MBProgressHUDDelegate

之后

MBProgressHUD *HUD;
.m文件中的

//将此代码添加到要显示的位置...

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];
    HUD.delegate = self;
    HUD.labelText = @"Authorizing...";
    [HUD show:YES];

当您的流程结束用于隐藏..

[HUD Hide:YES];

并在你的m文件中设置隐藏委托..

- (void)hudWasHidden:(MBProgressHUD *)hud {
    // Remove HUD from screen when the HUD was hidded
    [HUD removeFromSuperview];
    [HUD release];
    HUD = nil;
}

快乐的编码......