我在加载数据时使用MBProgressHUD
,用户可以在此过程中按另一个标签按钮。 MBProgressHUD
仅禁用视图内容。
我检查了其他帖子,但没有看到任何帮助我禁用标签按钮。
我尝试将tabbaritem.userInteractionEnabled
设置为NO
,但我找不到访问该方法的方法。我可以在故事板中执行此操作,但无法将其切换回YES
。
我的问题是;从我的viewController有没有办法访问tabbarcontroller.tabbaritem.userInteractionEnabled
?
答案 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];