IOS 5 MBProgressHUD在加载数据时禁用标签栏按钮。 (userInteractionEnabled = NO)

时间:2012-08-10 05:34:17

标签: ios5 tabbarcontroller mbprogresshud

我在加载数据时使用MBProgressHUD,用户可以在此过程中按另一个标签按钮。 MBProgressHUD仅禁用视图内容。 我检查了其他帖子,但没有看到任何帮助我禁用标签按钮。

我尝试将tabbaritem.userInteractionEnabled设置为NO,但我找不到访问该方法的方法。我可以在故事板中执行此操作,但无法将其切换回YES

我的问题是;从我的viewController有没有办法访问tabbarcontroller.tabbaritem.userInteractionEnabled

2 个答案:

答案 0 :(得分:0)

这是一种简单的方法

 [[[self tabBarController] tabBar] setUserInteractionEnabled:NO];

如此链接中所述:How can I make the tabbar action hidden when the view is loading?

适用于MBProgressHUD

答案 1 :(得分:0)

我使用类别:

的UIViewController + MBProgressHUD.h

#import <UIKit/UIKit.h>

@class MBProgressHUD;

@interface UIViewController (MBProgressHUD)

- (MBProgressHUD *)showHUD;
- (MBProgressHUD *)showHUDFromTitle:(NSString *)title;
- (MBProgressHUD *)showHUDFromTitle:(NSString *)title completedImage:(BOOL)completedImage;
- (void)hideHUD;

@end

和UIViewController + MBProgressHUD.m

#import "UIViewController+MBProgressHUD.h"
#import <MBProgressHUD/MBProgressHUD.h>

@implementation UIViewController (MBProgressHUD)

- (MBProgressHUD *)showHUDFromTitle:(NSString *)title {
    UIView *view;
    if (self.tabBarController.view != nil) {
        view = self.tabBarController.view;
    } else if (self.navigationController.view != nil) {
        view = self.navigationController.view;
    } else {
        view = self.view;
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:NO];
    hud.labelText = title;
    return hud;
}

- (MBProgressHUD *)showHUD {
    return [self showHUDFromTitle:NSLocalizedString(@"Loading", @"Loading")];
}

- (MBProgressHUD *)showHUDFromTitle:(NSString *)title completedImage:(BOOL)completedImage {
    MBProgressHUD *hud = [self showHUDFromTitle:title];
    if (completedImage) {
        UIImage *checkmarkImage = [UIImage imageNamed:@"37x-Checkmark"];
        UIImageView *checkmarkImageView = [[UIImageView alloc] initWithImage:checkmarkImage];
        hud.customView = checkmarkImageView;
        hud.mode = MBProgressHUDModeCustomView;
    } else {
        hud.mode = MBProgressHUDModeText;
    }
    return hud;
}

- (void)hideHUD {
    [MBProgressHUD hideAllHUDsForView:self.tabBarController.view animated:NO];
    [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:NO];
    [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
}

示例:

[self showHUD];
[self hideHUD];