Search code examples
iosuitabbarcontrollersidebar

SideMenu and Tabbar in one iOS application?


I am trying to implement custom tab bar and custom side menu in one iOS application, like in the new Facebook iOS application. I tried with following links https://github.com/mikefrederick/MFSideMenu and https://github.com/isaacueca/3dglobe/tree/4648fed5915cef53c58f3e54efadf0f512446e59/xCode/UniversialGlobe/Classes with DDKCustomTabbar classes, however when I am trying to put them both using this code:

[self.window addSubview:sideMenu.view];

[self.window addSubview:tabbar.view];

tabbar overlays the sideMenu and opposite.


Solution

  • A few quick points,

    Your trying to add them both to the window, which is almost certainly not what you want. Instead you want to set a single root view controller on the window.

    Now looking quickly at those 2 projects, what you'll need to do is create a menu view controller with a tab bar view controller as the center view controller. Then set the menu view controller as the root view controller of the window. Here is a very rough example of how you might do this.

    GTabBar *tabBarViewController = [[GTabBar alloc] initWithTabViewControllers:@[<Tab View Controller>] tabItems:@[<TabBarItems>] initialTab:0];
    
    YourLeftSideBarMenuViewController *leftMenuViewController = [[YourLeftSideBarMenuViewController alloc] init];
    YourRightSideBarMenuViewController *rightMenuViewController = [[YourRightSideBarMenuViewController alloc] init];
    MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
                                                    containerWithCenterViewController:tabBarViewController
    
                                                    leftMenuViewController:leftMenuViewController
                                                    rightMenuViewController:rightMenuViewController];
    
    self.window.rootViewController = container;
    

    Have a look at the basic demo included in the menu MFSideMenu project.

    I'd also suggest reading up a bit on how UIKit works, so you understand the difference between a window, view, viewController etc...

    Apple has a pretty detailed guide that will give you the basics: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AppDesignBasics/AppDesignBasics.html#//apple_ref/doc/uid/TP40007072-CH2-SW1