haluzak
haluzak

Reputation: 1143

UITabBarController - don't show the view

I'm creating an iPhone app with UITabBarController.
What I want to achieve is that when I tap some items on tabbar I don't want them to activate new view, instead of it I want them to run some functionality in the current view. For example I have a view with map active and when I click some item on tabbar I want it to locate the current position on the map.
I don't know if using UITabBarController is the best solution for this. I'll also want 1 item to swap between 2 views (map / list).
Would it be better to use some kind of ToolBar on bottom or anything completely different?
I don't think there is any code needed, but I've got a UITabBarViewController app created and I created a UITabBarControllerDelegate like this:

@interface MainTabBarControllerDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

and

@implementation MainTabBarControllerDelegate

@synthesize tabBarController, window;

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    tabBarController.delegate = self;
    [window addSubview:tabBarController.view];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

}

@end

But I don't know how to achieve the functionality. Thanks.

Upvotes: 0

Views: 814

Answers (1)

tipycalFlow
tipycalFlow

Reputation: 7644

You're right, you don't need a UITabBarController for this. A UIToolbar or your own custom UIView would be enough. But if you want to use UITabBarController, you'll have to override its usual functioning:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
return NO; //do not select any view controller here
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
  // find which tab was tapped here and handle the map's current position 
  // location operation accordingly
}

You can also refer to this link for more tips...

Upvotes: 1

Related Questions