Reputation: 362
I have a view that has a navigation bar on the top, 4 buttons in the middle for the menu, and a tab bar navigation on the bottom.
When only the tab bar items are used everything works, but when I load one of the views via the button the view remains when the tab bar item is pressed.
I'm new to ios so I may not be explaining it that well. I'm attaching a couple pictures to show what I mean.
I'm assuming that what I have to do to resolve is to intercept the Home button being pressed on the tab bar and tell it to dismiss the previously loaded view. I could be out to lunch on this.
Please let me know how to make the home button on the tab bar load the initial view even if one of the buttons were pressed to load another view.
Here's what my storyboard looks like. I used the Editor->Embed TabbarController.
** Update: Still working on trying to resolve this. I attempted to set the tab bar controller delegate via the app delegate as per some Q/A on stackoverflow but it didn't seem to make a difference. There is another approach I should be taking if I want to have a main home screen with buttons to various sections and those sections have a navigation and Tab bar controllers?
Upvotes: 0
Views: 2276
Reputation: 362
I managed to esolve the issue but I had to start over. I used the tab bar application template to start. Then on each view in the storyboard I selected "Editor->Embed->Navigation Controller". to add a navigation controller to each of the tab bar's views. On the initial view I created buttons and control dragged from them to each of the views to link them.
I then updated the following files:
AppDelegate.h
@interface NRMAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
tabController.delegate = self;
return YES;
}
MyViewController.m
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UINavigationController *navcon = (UINavigationController*)tabBarController.selectedViewController;
[navcon popToRootViewControllerAnimated:NO];
}
Also added an IBAction to the buttons to change the tab selected when the button is pressed.
- (IBAction)firstButtonPressed:(id)sender {
[self.tabBarController setSelectedIndex:1];
}
I tested it on the simulator, iPhone 5, and iPod touch 3rd generation.
Upvotes: 0
Reputation: 20021
If showing the video page on push .Then in ths selector action of the back button
add
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 0
Reputation: 971
I can see that you are using UINavigationController for going to next view (Video) instead of using UITabBarController.
You should use TABBarController method.
Upvotes: 0
Reputation: 12787
You need to add a line of code in tab bar item tapped event
Use popToRootViewController method here on the navigation controller of tab bar item.
You can find navigation controller object from tab Bar like this
UINavigationController *navcon = (UINavigationController*)myTabBarController.selectedViewController;
the use popToRootViewController
[navcon popToRootViewControllerAnimated:NO];
You can use this delegate for this code
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
Upvotes: 3