iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

Delegate to the left viewcontroller from the main viewcontroller #35

Closed gangelo closed 7 years ago

gangelo commented 7 years ago

I am trying to find a way to delegate to the left view controller (menu) from the main view controller. Basically, my left menu has a menu option called "Refresh" in which, when clicked, I was hoping to dismiss the menu and call a "refresh" member within the main view controller that refreshes the data in the table view controller on that screen. I am sure there are other ways to do this that don't have to involve all this, but it seems the right place to put the option for my app. Is this possible?

iDevelopper commented 7 years ago

Of course it is possible. No delegate needed to do that, simply call the method refresh from left view controller. Do you use Swift or ObjC?

gangelo commented 7 years ago

Swift 3

iDevelopper commented 7 years ago

Assuming your main view controller is embedded in a navigation controller:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //...
        //...
        let nc = self.revealViewController()?.mainViewController as? UINavigationController
        let controller = nc?.topViewController as? YourMainViewController
        controller?.refresh()
        self.revealViewController()?.hideLeftView(animated: true)
        //...
    }
gangelo commented 7 years ago

I will give it a try tonight thank you very much. I’ll let you know how it goes.

gangelo commented 7 years ago

Worked great ty!