I am new to Iphone and I have started an application in which I have added a custom tab bar which has to load to some particular page only. The tab bar works as per my expectation. Now the problem is that, when I navigate to other pages the tab bar keeps on showing and it cause serious problem for me... Here is my implementation
In .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
In .m, i am implementing the tab as:
- (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;
}
}
And when I implement a button to go to some other page, the tab bar keeps showing. Here is the button implementation in EditTabViewController.m file.
- (IBAction)goToHome:(id)sender {
homeBtn = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil];
[self.view addSubview:homeBtn.view];
}
Per Apple's rules, a TabBarController is supposed to be the main container. Plus, if you just implement a custom UITabBar
, are you using that to push the user into other views? If so, if the UITabBar
disappears, how does the user ever return?
If you only want the bar visible when a particular page is visible, why not implement a UINavigationController
(as the main container) and have the root UIViewController
implement a UIToolbar
that performs the same functions. Then, when you navigate to another page (I'm assuming here that you mean a new screen, not a different page in a UIPageControl
or a web page in a UIWebView
), you push in a new UIViewController
that doesn't contain the UIToolbar
.
Kind of like this:
--UINavigationController
|
-->UIViewController as RootViewController --> Contains UIToolbar
|
-->Pushes UIViewController --> Has no UIToolbar
Edit/Update
I just saw your code, and I'm not sure I understand what you're trying to achieve. I think you might be trying to somehow implement behavior similar to a UINavigationController
without actually using one.
Edit/Update #2 I think you are wanting behavior that can be implemented like this:
UINavigationController (containing IconMenuViewController as RootViewController)
|
--> PageViewController (push into this from any icon touch in IconMenuViewController)
--> Contains UIToolbar/UITabBar
If you use the hierarchy above, the UINavigationController
will automatically provide you with the NavigationBar
at the top of the screen and give you a back button. As long as you make the UIToolbar
or UITabBar
part of the PageViewController
, it should appear and disappear with its view controller as you push and pop it. Does that make sense?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.