iPhone 如何启用或禁用 UITabBar
我有一个带有标签栏的简单应用程序,它根据用户输入禁用一个或多个栏项目。我知道我需要使用我尝试过使用的 UITabBarDelegate 。但是,当我调用委托方法时,我收到未捕获的异常错误 [NSObject doesNotRecognizeSelector]。我不确定我做得是否正确,或者我没有错过什么。任何建议。
我现在所拥有的如下:
WMViewController.h
#import <UIKit/UIKit.h>
#define kHundreds 0
@interface WMViewController : UIViewController <UITabBarDelegate, UIPickerViewDelegate, UIPickerViewDataSource>{
}
@end
WMViewController.m
#import "WMViewController.h"
#import "MLDTabBarControllerAppDelegate.h"
@implementation WMViewController
- (IBAction)finishWizard{
MLDTabBarControllerAppDelegate *appDelegate = (MLDTabBarControllerAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setAvailabilityTabIndex:0 Enable:TRUE];
}
MLDTabBarControllerAppDelegate.h
#import <Foundation/Foundation.h>
@interface MLDTabBarControllerAppDelegate : NSObject <UITabBarDelegate>{
}
- (void) setAvailabilityTabIndex: (NSInteger) index Enable: (BOOL) enable;
@end
MLDTabBarControllerAppDelegate.m
#import "MLDTabBarControllerApplicationDelegate.h"
#import "MyListDietAppDelegate.h"
@implementation MLDTabBarControllerAppDelegate
- (void) setAvailabilityTabIndex: (NSInteger) index Enable: (BOOL) enable
{
UITabBarController *controller = (UITabBarController *)[[[MyOrganizerAppDelegate getTabBarController] viewControllers ] objectAtIndex:index];
[[controller tabBarItem] setEnabled:enable];
}
@end
我得到了一个看起来不错的控制器对象,但在 [[controller tabBarItem]setEnabled:enable]; 上崩溃了;
我错过了什么...
任何建议
谢谢,
I have a simple app with a tab bar which based upon user input disables one or more of the bar items. I understand I need to use a UITabBarDelegate which I have tried to use. However when I call the delegate method I get an uncaught exception error [NSObject doesNotRecognizeSelector]. I am not sure I am doing this all right or that I haven't missed something. Any suggestions.
What I have now is the following:
WMViewController.h
#import <UIKit/UIKit.h>
#define kHundreds 0
@interface WMViewController : UIViewController <UITabBarDelegate, UIPickerViewDelegate, UIPickerViewDataSource>{
}
@end
WMViewController.m
#import "WMViewController.h"
#import "MLDTabBarControllerAppDelegate.h"
@implementation WMViewController
- (IBAction)finishWizard{
MLDTabBarControllerAppDelegate *appDelegate = (MLDTabBarControllerAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setAvailabilityTabIndex:0 Enable:TRUE];
}
MLDTabBarControllerAppDelegate.h
#import <Foundation/Foundation.h>
@interface MLDTabBarControllerAppDelegate : NSObject <UITabBarDelegate>{
}
- (void) setAvailabilityTabIndex: (NSInteger) index Enable: (BOOL) enable;
@end
MLDTabBarControllerAppDelegate.m
#import "MLDTabBarControllerApplicationDelegate.h"
#import "MyListDietAppDelegate.h"
@implementation MLDTabBarControllerAppDelegate
- (void) setAvailabilityTabIndex: (NSInteger) index Enable: (BOOL) enable
{
UITabBarController *controller = (UITabBarController *)[[[MyOrganizerAppDelegate getTabBarController] viewControllers ] objectAtIndex:index];
[[controller tabBarItem] setEnabled:enable];
}
@end
I get what appear to be a good controller object but crash on the [[controller tabBarItem]setEnabled:enable];
What am I missing...
Any suggestions
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要实现 UITabBarControllerDelegate,特别是
对于那些应该禁用的 viewController 并返回 NO。
You need to implement the UITabBarControllerDelegate, in particular
and return NO for those viewControllers that should be disabled.
self.tabBarController?.tabBar.userInteractionEnabled = false
将快速完成self.tabBarController?.tabBar.userInteractionEnabled = false
will do it in swift您也可以通过选择父视图控制器来选择选项卡栏控制器。我这样做不需要实现任何代表。
You can select the tab bar controller by selecting the parent view controller too. I did this without the need of implementing any delegates.