我在加载数据时使用MBProgressHUD
,用户可以在此过程中按另一个选项卡按钮。 MBProgressHUD
仅禁用视图内容。我检查了其他帖子,但没有看到任何帮助我禁用选项卡按钮的内容。
我试图将tabbaritem.userInteractionEnabled
设置为 NO
,但我找不到访问它的方法。我可以在故事板中执行此操作,但无法将其切换回YES
.
我的问题是;从我的角度来看控制器有什么方法可以访问tabbarcontroller.tabbaritem.userInteractionEnabled
吗?
我使用类别:
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];
这是一种简单的方法
[[[self tabBarController] tabBar] setUserInteractionEnabled:NO];
如此链接中所述:如何在加载视图时隐藏选项卡栏操作?
与MBProgressHUD配合使用效果很好
优雅地显示 UITabBarController
的 HUD ,因为用户交互将完全由MBProgressHUD
控制,直到调用hideAnimated:
:
// Show HUD from Tab Bar, to disable the tab bar items:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.tabBarController.view
animated:YES];
// Do some time-consuming stuff:
...
// Hide HUD and enable tab bar items:
[hud hideAnimated:YES];