iOSDev
iOSDev

Reputation: 3617

How to display different view everytime when a tabbar item is clicked in UITabBarBased app?

I want screen 1 to be shown when tabbaritem 1 is clicked and if I change some settings, i go to different view, , when I click the tabbaritem 1 again I want to show screen 2.

I have a UITabbar based app and the MainWindow.xib has different tabs loaded before with views.

How do I change it programmatically?

Please help

Upvotes: 1

Views: 691

Answers (3)

Valeriy Van
Valeriy Van

Reputation: 1865

Turn MainWindow or AppDelegate into UITabBarDelegate, than use - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item to caught tab selections. When tab you need is selected, use image property of UITabBarItem to set image you like.

Upvotes: 0

Nishant B
Nishant B

Reputation: 2897

Implement below method in your App Delegate

- (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {

    UINavigationController *nc;
    nc = viewController;

    if(controller.selectedIndex == 3){
        [[nc.viewControllers objectAtIndex:0] replaceSubView];
    }
}

Here, if(controller.selectedIndex == 3)

3 = your viewcontroller index in which you want to change subview.

And "replaceSubView"

is your method in view controller in which you want to change subview.

Let me know in case of any difficulty.

Cheers.

Upvotes: 0

user387184
user387184

Reputation: 11053

just put the code for the views to be created in the method viewWillAppear instead of viewDidLoad. This is being called each time go go back to your tab 1

Upvotes: 1

Related Questions