2012-09-03 51 views
1

我有一个显示在uitableview中的歌曲标题以及“购买”按钮列表。当点击该按钮时,我显示MBProgressHUD.But有时它不被显示。同时它禁用用户交互作为它在下面的代码中。有时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]; 

    } 

回答

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 fil中设置隐藏代理E也..

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

快乐编码...

+0

感谢您的答复。和我的代码中有什么问题,请让我知道 – user198725878

+1

我认为如果你使用navigationController,然后MBProgressHUD添加在self.navigationController.view,并且在你的代码中你没有设置代码。 –