我有一个带标签栏的简单应用程序,根据用户输入禁用一个或多个条形项.我知道我需要使用我尝试使用的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
Run Code Online (Sandbox Code Playgroud)
我得到了一个看起来很好的控制器对象,但在[[controller tabBarItem] setEnabled:enable]上崩溃了;
我错过了什么......
有什么建议
谢谢,
小智 28
// Disable
UITabBarController.tabbar.userInteractionEnabled = NO;
// Enable
UITabBarController.tabbar.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
您需要实现 UITabBarControllerDelegate,特别是
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
Run Code Online (Sandbox Code Playgroud)
并为那些应该禁用的 viewController 返回 NO。
| 归档时间: |
|
| 查看次数: |
9149 次 |
| 最近记录: |