我是 Iphone 新手,我已经启动了一个应用程序,我在其中添加了一个自定义标签栏,该标签栏只能加载到某些特定页面。标签栏按我的预期工作。现在的问题是,当我导航到其他页面时,标签栏继续显示,这给我带来了严重的问题......这是我的实现
在.h中:
#import <UIKit/UIKit.h>
@class MainMenuViewController;
@interface RoutineListViewController : UIViewController<UITabBarDelegate>{
MainMenuViewController *homeBtn;
UITabBar *mainTabBar;
UIViewController *routineTabViewController;
UIViewController *calendarTaViewController;
UIViewController *editTabViewController;
}
@property (nonatomic, retain) IBOutlet UITabBar *mainTabBar;
@property (nonatomic, retain) IBOutlet UIViewController *routineTabViewController;
@property (nonatomic, retain) IBOutlet UIViewController *calendarTabViewController;
@property (nonatomic, retain) IBOutlet UIViewController *editTabViewController;
- (IBAction)goToHome:(id)sender;
@end
在 .m 中,我将选项卡实现为:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch (item.tag) {
case 1:
if (routineTabViewController == nil) {
self.routineTabViewController =[[RoutineListViewController alloc] initWithNibName:@"RoutineListViewController" bundle:nil];
[self.view insertSubview:routineTabViewController.view belowSubview:mainTabBar];
routineTabViewController = nil;
[routineTabViewController release];
}
break;
case 2:
if (calendarTabViewController == nil) {
self.calendarTabViewController =[[CalendarTabViewController alloc] initWithNibName:@"CalendarTabViewController" bundle:nil];
[self.view insertSubview:calendarTabViewController.view belowSubview:mainTabBar];
calendarTabViewController = nil;
[calendarTabViewController release];
}
break;
case 3:
if (editTabViewController == nil) {
self.editTabViewController =[[EditTabViewController alloc] initWithNibName:@"EditTabViewController" bundle:nil];
[self.view insertSubview:editTabViewController.view belowSubview:mainTabBar];
editTabViewController = nil;
[editTabViewController release];
}
break;
default:
break;
}
}
当我实现一个按钮转到其他页面时,标签栏一直显示。这是 EditTabViewController.m 文件中的按钮实现。
- (IBAction)goToHome:(id)sender {
homeBtn = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil];
[self.view addSubview:homeBtn.view];
}