handsomecode / InteractiveSideMenu

iOS Interactive Side Menu written in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using with tabbar

opened this issue · comments

Hello i have one tabbar and navigation bar for each item inside tabbar.

var contentList = [MenuItemContentViewController]()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController
contentList.append(tabbarVC as MenuItemContentViewController)

I am trying to add tabbar but it gives me an error. Do you know how can i use with tabbar ?

Hi @berkerbilgi

It looks like you try to use incompatible types because UITabBarController cannot be an inheritor from MenuItemContentViewController that is required to put in contentList.

So at the moment current version of the library doesn't support working with UITabBarController. Sorry about it.

But there is a workaround you might use. You can create TabBarVC that is an inheritor from MenuItemContentViewController and then to add actual UITabBarController as a child view controller. Here is an example:

    class TabBarViewController: MenuItemContentViewController {
        override func viewDidLoad() {
            super.viewDidLoad()
       
            let innerTabBarVC = self.storyboard!.instantiateViewController(withIdentifier: "InnerTabBar") as! InnerTabBarViewController
        
            self.addChildViewController(innerTabBarVC)
            self.view.addSubview(innerTabBarVC.view)
        }
    }

    class InnerTabBarViewController: UITabBarController {}

Thanks for letting us know about this issue! Feel free to send us pull requests!

For those who might have been struggling with this approach:

  1. If TabBarViewController is not a viewController in the StoryBoard, the self.storyboard! should be changed to
    let someStoryboard = UIStoryBoard(name: "Main", bundle: nil)
    let innerTabBarVC = someStoryboard.instantiateViewController(withIdentifier: "InnerTabBar") as! InnerTabBarViewController

  2. The showMenu() function cannot be called from the viewController which is embedded in a TabBarController or NavigationController (even if it is inherited from the MenuItemContentViewController). Because its parent is either UITabBarController (or UINavigationController and they could not be cast to MenuContainerViewController. (Dont worry if you didn't understand this)
    So the solution is:
    Write a function in the TabBarViewController above (or anything else in your case) and put the showMenu() in it:

public func foo() {
   showMenu()
}

And in your main viewController every time you want to show menu use the code below:

if let parentVC = self.parent?.parent as? TabBarViewController {
     parentVC.foo()
} else {
     print("Oops!")
}

Have FUN!
Amin

@amiinous Thanks for sharing some details about described approach!

Btw, in the near future, we are going to release next version of our library where we simplify working with TabBarVC and NavigationVC. So, stay tuned on, please.

Hi Andrey,

is it possible to share the code for the sample gif in the Readme. (i.e. the MenuViewController) ?

Hi @amiinous,

This gif is just a sample of using SideBar menu. It's a part of commercial projects and, unfortunately, we haven't enough rights to share its code.

And we are ready to answer any specific questions concerning implementation of MenuViewController if you have them.

Thank you for your comments.

Thanks Olga. I understand.
Cant wait to see upcoming commits.

UITabBarController and UINavigationViewController is now supported in SideMenu 2.0. Please, take a look into the new version and simplified approach of adding menu items. Check Sample, if necessary.

Good luck!

Congrats ;)
is cocoapod update available?
(It shows InteractiveSideMenu 1.0 instead of 2.0)

We are working on it right now. Will be ready soon :)

Yeah, now it's ready https://cl.ly/2V3U0y0H0E3Y. Please, check it and close the issue if everything is ok.

Have fun.

README needs some updating.
or a migration guide.
Spent a good bit looking at the sample to get my 1.0 version working.

@DaveInTO
Thanks for your comments. We will add a migration guide soon.

Hi @DaveInTO,

You could use ChangeLog file to migrate to the newer version. Weren't Migration Notes from that file helpful enough?

It's very important for us to hear your opinion to be able to improve guides if it's necessary. Thanks a lot!

All good now, when i used the sample as a guide, it didn't have UIViewController.
So i replaced all the MenuViewController with SideMenuItem...
And all view objects became unknown.

Easy fix once I prepended UIViewController everywhere.

Ok, thank you!