Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
I have UITabBar based application with 3 tabs which are UINavigationControllers.

When user clicks certain button on tab1 i push another viewcontroller (so there is Back button in navigationbar).
then i click on tab2 and back to tab1. State of pushed viewcontroller is the same (backbutton is visible).
How i can make so that when user clicks on tab1 again - it will have initial view (not pushed view)?

thanx
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Easiest solution would be to implement the UITabBarControllerDelegate method tabBarController:didSelectViewController: and then call popToRootViewControllerAnimated: on the navigation controller.
 

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
Easiest solution would be to implement the UITabBarControllerDelegate method tabBarController:didSelectViewController: and then call popToRootViewControllerAnimated: on the navigation controller.

Doesn't work.
here is hierarchy of controls:
UITabBarController
-UITabBar

-UINavigationController (shown in tab1)
--UINavigationBar
--UIViewController (<UITableViewDelegate,UITabBarControllerDelegate>)
---UIView
----UITableView

-UINavigationController (shown in tab2)

-UINavigationController (shown in tab2)

In didSelectRowAtIndexPath i push another UIViewController from different NIB.
If i try to add didSelectViewController into UIViewController - it doens't work.

How i can change view to initial state (not pushed) after switching between tabs?
 

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
i attached example of application.

if u click on any item row in list - new view will be pushed.
then click on another tab and again on List tab.
i need to show view with tableview and not details view (though if u click on list 2 times - tableview will be shown)

How it can be done?

thanx
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I'll just give you code from my project which has worked for me:
Code:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    UINavigationController *navController = (UINavigationController *)viewController;
    if (![navController isKindOfClass:[UINavigationController class]])
        return;
	
    // did become inactive
    if (m_activeViewController != nil && [m_activeViewController respondsToSelector:@selector(viewControllerDidBecomeInactive)])
        [m_activeViewController viewControllerDidBecomeInactive];
    // set active
    m_activeViewController = navController.topViewController;
    // did become active
    if ([m_activeViewController respondsToSelector:@selector(viewControllerDidBecomeActive)])
        [m_activeViewController viewControllerDidBecomeActive];
}

m_activeViewController is an ivar which conforms to a custom protocol (that implements viewControllerDidBecomeActive and viewControllerDidBecomeInactive). It allows each view controller in the tab (more specifically the top view controller in each navigation controller) to run code when it becomes active or inactive. If you setup something like this you could get it to work.
 

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
The problem is that when i added UITabBarControllerDelegate into my UIViewController and added - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

this method is not called.
 

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
Did you set the tab bar controller's delegate?

yes, i did, u can see source code in attached example.

Problem was that i didn't connect UITabBar in xib with controller class.
so it is solved
 

lrusty

macrumors newbie
Aug 24, 2008
1
0
Hi pashik

Can you please share the code? I am trying to create an application where the tab bar is displayed only after a few screens go by! Tried many things but to no avail!! Please help!

yes, i did, u can see source code in attached example.

Problem was that i didn't connect UITabBar in xib with controller class.
so it is solved
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.