UITabbarController with MoreNavigationController , PoptoRootViewController issue - iphone

Kindly help me with this issue .
I am using tabbarcontroller in my App,
[tabBarController setViewControllers:tabs];
tabs Contain array of viewcontrollers (6 viewcontrollers).
It automatically created more button.
ISSUE
When I open any viewcontroller from more button and then open any other controller from index 0 to 2 , and then press more button it maintain the last opened viewcontroller .
For Example:
more button tableviewcontroller
screen :
Now when i press Contacts let say
Now when user press any other tabbar like feature tab bar
Now when user go back to more tab it shows the contact's viewcontroller
But i want the app to poptorootviewcontroller when user back again to more tabbar , and simply more tableviewcontroller.

You can do this by in the ViewWillDisappear method of view controller in More tab, call method to pop this view out of MoreViewNavigationController, like this:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController popViewControllerAnimated:NO];
}

May be too late but here it is for future reference
UITabController has a tabBar property and it has a delegate which tells you when a tabitem is tapped
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
Tab bar also has another property "items" which lists the visibile tabs. Find the index of the selected tab item in items in the delegate method implementation and if the index is 4 which is more button then call tab [controller.moreNavigationController popToRootViewController]

Related

iPhone- How to get the main view (1st view) every time when we switching form one tab to another tab

In my iPhone app, I have used tabbarcontroller in that i have 4 tabs for four different items
In each tab i have different views navigate transaction in those.
my requirement is, when i switch form on tab to another tab by taping on tabbar item.
T*the main view (first view ) of each tab has to be appeared instead of currently working view.*
For ex:
I select tab 3 there i do some operations and navigate to some 2nd view in the third tab.
and then i secet tab 4 and then again tab3.. then the previously woriking view view 2 presents in tab3,
But i need to present 1st view at any time when i select tab 3 (Same like in any other tabs)
how to do..
Make a subclass of UINavigationController, change the class of any navigation controllers you have in your storyboard to that class, and put this code in that subclass:
-(void)viewDidDisappear:(BOOL)animated {
[self popToRootViewControllerAnimated:NO];
}
Whenever you click on another tab, this method will be called, and it will reset the navigation stack back to the root view controller.
Set your view controller or appdelegate as delegate of your tabbarcontroller. implement this delegate function
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
int selectedIndex = tabBarController.selectedIndex;
NSArray *tabbarControllers = tabBarController.viewControllers;
//Then replace tabbarControllers[selectedIndex] by your new view controller(with navigation controller)
tabBarController.viewControllers = Your replaced Array;
}

Unable to remove BackButton in Navigation controller using Storyboard in ios

I am new to iOS,
I am developing shopping App for IPhone using Storyboard,
Here is the snapshot of my App,
TabBarController contains 4 Tab with NavigationController
When i open Tab1(let say class1) it contains TableView, onclick of tableview it will take me to Detail page with title and back button on NavigationBar (I am adding title and back button programatically in ViewWillAppear method) after this when i hit back button i navigates to previous page properly, this is working fine..
My problem is When i open Tab1(i.e class1) and when i navigates to Detail page after selecting a row in tableview, in a Detail page, BackBtn and title will be added in NavigationBar bcoz ViewWillAppear method will be called, and when i hit Tab2 before hitting Backbtn, i am navigates to class of Tab2 and thn when i comes back to Tab1 and now i clicks on back button i am navigating to previous page of my Tab1 class (i.e class1) but on class1 back Button and title of Detail page is there on my class1 i am unable to hide it...
You can see in the 2nd image BackBtn and Title is there in Class1..
What's the problem ?
just hide that backButton in viewWillAppear: method of Class1 like bellow...
[self.navigationItem setHidesBackButton:YES animated:YES];
or
[self.navigationItem setHidesBackButton:YES];
UPDATE:
if you add custom button to the UINavigationBar then just remove that button like bellow...
self.navigationItem.leftBarButtonItem = nil;
and if you want to remove right bar button then use bellow another code like above...
self.navigationItem.rightBarButtonItem = nil;
i hope this helpful to you...
[btnBack setHidden:YES] in viewWillDisapper: method in Detail page
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
Will give you which item you are currently selecting.
You can work around if you cant fix it by popping to root view controller and pushing it again. And make sure you are not adding a subview in place of pushing a view controller.

TableView in NavigationBar and Tabbar Switch Between Tabs Gets Bad Access

I'm building an app that combines tabbar and navigation bar. In one of tabs, I have a UIButton and by touching it, I push a Tableview into stack of navigationcontroller. Then, without returning to the root view controller manually by pressing Back buttons I change to another tab from tabbar and when I come back to the tab with the tableview inside, I get bad access error.
I've already tried popping the tableview from navigation controllers stack, or not releasing the tableview but I could't make it.
Thanks...
Assuming you've created your tabBar and Navigation Controllers in the AppDelegate, you can code your app to return each tab to the root view when it is selected.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (viewController == firstViewNavigationController) {
[firstViewNavigationController popToRootViewControllerAnimated:NO];
} else if (viewController == secondViewNavigationController) {
[secondViewNavigationController popToRootViewControllerAnimated:NO];
}
}
I am using this and it is working fine in my app. I am releasing my Navigation Controllers in the dealloc method. I have also made my AppDelegate conform to the UITabBarDelegate protocol.

Double Clicking on UITabBarControllers Tab goes to root of Navigation controller

I have a UITabBarController setup with 2 UINavigationControllers.
One UINavigationController has One UIViewController, the other UINavigationController has Two UIViewControllers. If you then navigate to the second UIViewController and click the Tab that is already selected it bring you to the root of the UINavigationController (This would be the first UIViewController).
Is there a way to stop this from happening? I do not want the user to be able to click an already selected Tab to go to the root of the Navigation Controller.
To do this you need to implement a function in your app delegate to pick up the tabbar delegate calls.
In your app delegate.m file, in the didfinishlaunching method, add this line
[tabBarController setDelegate:self];
then implement this method (also in your app delegate):
- (BOOL)tabBarController:(UITabBarController *)theTabBarController shouldSelectViewController:(UIViewController *)viewController
{
return (theTabBarController.selectedViewController != viewController);
}
This gets called as part of the tab delegate protocol and will stop the selection of a tab if its already the selected one.
Hope that helps.

Is it possible to refresh the TabbarController when a user selects a particular tab in iPhone?

I have a TabbarController with 3 tabs with each tab representing a navigation Controller. What I would like to do is when a user selects a particular tab the whole tabbar Controller should refresh.
To make it more clear...
When a user selects tab0 and navigates in that tab 2-3 times and then the user selects tab1. Now when the user again selects tab0 it retains the last viewed ViewController. Can
I make to show the first viewController in that tabbar NavigationController.
Can anyone help me in resolving this problem...
Any code will be very helpful...
Thanx in advance...
Plz help me.....
Set yourself as the tab bar delegate and implement tabBar:didSelectItem: as per below.
You can then popToRootViewController on your relevant ViewController:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item.tag == kRelevanTabBarIndex) {
[self.relevantNavController popToRootViewControllerAnimated:NO];
}
}
Cheers,
Rog