iPhone 如何启用或禁用 UITabBar

发布于 2024-08-29 07:17:54 字数 1562 浏览 9 评论 0原文

我有一个带有标签栏的简单应用程序,它根据用户输入禁用一个或多个栏项目。我知道我需要使用我尝试过使用的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫瑾少女 2024-09-05 07:17:54
// Disable    
UITabBarController.tabbar.userInteractionEnabled = NO;

// Enable
UITabBarController.tabbar.userInteractionEnabled = YES;
// Disable    
UITabBarController.tabbar.userInteractionEnabled = NO;

// Enable
UITabBarController.tabbar.userInteractionEnabled = YES;
流星番茄 2024-09-05 07:17:54

您需要实现 UITabBarControllerDelegate,特别是

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

对于那些应该禁用的 viewController 并返回 NO。

You need to implement the UITabBarControllerDelegate, in particular

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

and return NO for those viewControllers that should be disabled.

最笨的告白 2024-09-05 07:17:54

self.tabBarController?.tabBar.userInteractionEnabled = false 将快速完成

self.tabBarController?.tabBar.userInteractionEnabled = false will do it in swift

┾廆蒐ゝ 2024-09-05 07:17:54

您也可以通过选择父视图控制器来选择选项卡栏控制器。我这样做不需要实现任何代表。

self.parentViewController.tabBarController.tabBar.userInteractionEnabled = NO;

You can select the tab bar controller by selecting the parent view controller too. I did this without the need of implementing any delegates.

self.parentViewController.tabBarController.tabBar.userInteractionEnabled = NO;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文