handsomecode / InteractiveSideMenu

iOS Interactive Side Menu written in Swift.
Apache License 2.0
708 stars 163 forks source link

how to call Side menu from Child view Controller class #96

Closed patriksharma closed 6 years ago

patriksharma commented 6 years ago

Well I called Class A from side Menu and Menu icon is working fine from here. Now I Move to Class B from Class A using Navigation controller.

I added menu icon there but open side menu is not working from there. Any idea ?

patriksharma commented 6 years ago

I tried this code, but it doesn't work. Condition fails.

class NavigationViewController: UINavigationController, SideMenuItemContent {
}

class VideoUploadController: UIViewController {

    @IBAction func openMenu(_ sender: Any) {
        if let navigationViewController = self.navigationController as? SideMenuItemContent {
            navigationViewController.showSideMenu()
        }
    }
}
patriksharma commented 6 years ago

@rob5408 @AlexKorovyansky @johnroescher @alexzub @progn any one please help me to get this working

indiraAman commented 6 years ago

@patriksharma hello! I also have the same problem... did you solve it?

patriksharma commented 6 years ago

@indiraAman Yes, Solved it. IT took lot of time to understand but Take it this way.

They have default storyboardable. swift file which you need to include . Basically You need to create seprate storyboard file for each side menu. For example I have created a side menu with 4 options. Then I need to create 4 storyboard files and use. Then only it works for you

 static func storyboardNavigationController() -> UINavigationController {
        print ("name",defaultStoryboardName)
        let storyboard = UIStoryboard(name: defaultStoryboardName, bundle: nil)

       // guard let nc = storyboard.
        guard let nc = storyboard.instantiateInitialViewController() as? UINavigationController else {
             fatalError("Could not instantiate initial storyboard with name: \(defaultStoryboardName)")
        }

        return nc
    }
indiraAman commented 6 years ago

@patriksharma thanx, but unfortunately it didn't help me(( and i can't figure out why

patriksharma commented 6 years ago

@indiraAman Ok do a simple thing

1) Open sample code added in the -InterativeSideMenuproject folder 2) Now drag and dropStoryboardable.swiftfile into your project 3) Now drag and dropHostViewController.swiftandPOAMenuViewController.swift` into your project

In HostViewController class. Change this method with your Classes and Make seprate storyboard for each class.

    private func contentControllers() -> [UIViewController] {
     let myAccountViewController = myAccountViewController.storyboardNavigationController()
         let officeManualController = officeManualViewController.storyboardNavigationController()
    let curriculmController = curriculumViewController.storyboardNavigationController()
         let checkListController = checklistViewController.storyboardNavigationController()
        let employeeController = employeeListViewController.storyboardNavigationController()

        return [myAccountViewController,officeManualController,curriculmController,checkListController,employeeController]

I have created 5 side menu classes. So 5 storyboard files (Make sure you keep Same Name for storyboard) for example myAccountViewController.storyboard for myAccountViewController and in Storyboard file Make a tick Mark for is initial View Controller property .

I hope it helps you and work for you . Just follow the sample code they have created for navigation controller

indiraAman commented 6 years ago

@patriksharma it works) thanx! you helped me a lot!))))))

patriksharma commented 6 years ago

@indiraAman Nice to hear that from you :) Dua mein Yaad rakhna