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

Equivalent code SWRevealViewController in PBRevealViewController #73

Closed kgirl7 closed 5 years ago

kgirl7 commented 5 years ago

Hi! Hope you can help

I have a project with SWRevealViewController and I updated to PBRevealViewController. The menu show sections call from an api, when you click into the option, have to show you the section specific but in the Back button you have to go back to the MainViewcontrollerr and not the menu.

This is part of the code that I want to change:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    self.revealViewController().rearViewRevealWidth = UIScreen.main.bounds.size.width
   self.revealViewController().setFrontViewPosition(.rightMost, animated: false)

    if segue.identifier == "toSectionNewsSegue" {

        // Get reference to destination view controller
        let destinationVC = segue.destination as! SectionNewsViewController
        let selectedIndexPath = tableView.indexPathForSelectedRow!

        let sectionName = self.menu.items[(selectedIndexPath as NSIndexPath).section][(selectedIndexPath as NSIndexPath).row].name
        destinationVC.sectionToDisplay = self.menu.items[(selectedIndexPath as NSIndexPath).section][(selectedIndexPath as NSIndexPath).row].id
        destinationVC.sectionToDisplayName = sectionName

        // Change title of backItem
        let backItem = UIBarButtonItem()
        backItem.title = "  \(sectionName)"
        navigationItem.backBarButtonItem = backItem
    }
}

// MARK: Helpers
func sectionHeaderName(forSection section: Int) -> String {
    return self.menu.sections[section]
}

//MARK: - UINavigationControllerDelegate
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

    if toVC.isKind(of: MenuController.classForCoder()) {
        if operation == .pop {
            self.revealViewController().rearViewRevealWidth = 260
            self.perform(#selector(MenuController.setFrontView), with: nil, afterDelay: 0.01)
        }
    }
    return nil
}

@objc func setFrontView() {
    self.revealViewController().setFrontViewPosition(.left, animated: true)
}

The equivalent of these two functions, what is it?

[SWRevealViewController] self.revealViewController().setFrontViewPosition(.rightMost, animated: false) self.revealViewController().setFrontViewPosition(.left, animated: true)

I couldn't find the equivalent .rightMost and .left in the PBRevealViewController

[PBRevealViewController] self.revealViewController()?.setMainViewController(self, animated: true) self.revealViewController()?.setMainViewController(self, animated: true)

Currently the code sends me to the section without navigation bar (does not show the return button)

Hope can you help me!!

iDevelopper commented 5 years ago

Hi!

The equivalent code for setFrontViewPosition is revealLeftView() or revealRightView(). These functions will reveal the side view (left or right) or hide it if shown.

setMainViewController is for replacing the main view controller.

If you do not have a navigation bar, I think your segue destination is not a navigation controller, please check.

kgirl7 commented 5 years ago

Ok thank you!, I checked and it works with the function revealRightView, showing the Section News View and now appears the navigation bar but when I clicked on the Back Button, returns to the Menu View which is the "pb_left" (covering all the screen) (with the SWRevealViewController send me to the MainViewController) and I want to back to the MainViewController which is the "pb_main". I will add and screenshot to explain me better. Hope you can understand and help me!

My storyboard storyboardNews

iDevelopper commented 5 years ago

If you want to push a controller and come back to the main view controller, you have to push this controller with the navigation controller of the main view controller. That's all. When pushing use also revealLeftView(), so the left menu will be closed when coming back.