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

Problem calling right menu from another storyboard #64

Closed FedericoSub closed 5 years ago

FedericoSub commented 5 years ago

Hello, I’m trying to call a TableviewController with right menu from another storyboard but doesn’t work …. I call the button “vaiBtn” but nothing happens. I think it's my mistake but I can't solve.

This is the ViewController in storyboard named “Immersioni” where I call the TableView in storyboard “Main”:

// // PostViewController.swift // CSMApp // // Created by Federico Vivian on 10/02/2019. // Copyright © 2019 Club Sommozzatori Mestre. All rights reserved. //

import UIKit

class PostViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

@IBAction func vaiBtn(_ sender: Any) {

let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let desController = mainStoryboard.instantiateViewController(withIdentifier: "VetrinaTableViewController") as! VetrinaTableViewController let newFrontViewController = UINavigationController.init(rootViewController:desController) revealViewController()?.pushMainViewController(newFrontViewController, animated: true)

}

}


This is the viewDidLoad() of VetrinaTableViewController in the other Storyboard

override func viewDidLoad() {

    super.viewDidLoad()
    indiceRiga = 0

    rightButton.target = self.revealViewController()
    self.revealViewController()?.isRightPresentViewOnTop = false
    rightButton.action = #selector(PBRevealViewController.revealRightView)

    updateView()

    //MARK make navbar trasparent
    let bar:UINavigationBar! =  self.navigationController?.navigationBar
    bar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    bar.shadowImage = UIImage()
     self.tableView.addSubview(RefreshControl)
}

Thanks in advance. Federico

iDevelopper commented 5 years ago

No sure to understand.

1) How do you instantiate PBRevealViewController? Programmatically? 2) Which controller is in the main storyboard? (main, right ?) 3) Which controller is in the Immersioni storyboard? (main, right)

FedericoSub commented 5 years ago

1) yes 1. Programmatically 2) yes main and right 3) in Immersioni storyboard i have a ViewController with only a button "Pubblica in Vetrina" where i'd like put the return to VetrinaTableViewController .

This i VetrinaTableViewController in main storyboard where I'd like to return img_0483

This is in Immersioni storyboard where I select my dive number for display the detail img_0485

this is dive detail DiveTableViewController img_0486

from DiveTableViewController I go to PostViewController, this is PostViewController where if I push button "Pubblica in Vetrina" I should return to VetrinaTableViewController

img_0487 Archivio.zip

iDevelopper commented 5 years ago

Hum... Can you upload the whole project please?

FedericoSub commented 5 years ago

It's 140MB so this is a link in Dropbox

https://www.dropbox.com/s/6kpeh2i6eu2x1tr/CSMApp.zip?dl=0

Thanks

iDevelopper commented 5 years ago

Got it. I have a look.

iDevelopper commented 5 years ago

Sorry I do not find how to go to this view!

FedericoSub commented 5 years ago

logbook > Immersioni > #3 > Pubblica (button at the end) > Pubblica in Vetrina

FedericoSub commented 5 years ago

this is a Sreenrecording how you can finf the final view.... https://www.dropbox.com/s/4n3u0p9615oz8s6/ScreenRecording_02-12-2019%2013-37-12.MP4?dl=0

thanks

iDevelopper commented 5 years ago

Well, RevealViewController is nil in PostViewController, but that, I suspected it from the beginning.

You have no more reveal view controller as soon as you present a modal controller. Because the new presented controller is no more in the same stack.

This is the case when you present another navigation view controller with a show segue type in a storyboard. For example, to present ListaDiveTableViewController, you use a show segue to the entry point of immersioni storyboard which is a navigation controller. So ListaDiveTableViewController is presented modally and you lost the reveal view controller.

Now there are two solutions for you:

Either you continue like this, modally presenting the controllers and you have to pass the reference of the reveal view controller in the prepareforsegue method to the destination controller, or you remove too many navigation controllers so that the presented controllers remain in the stack. I suggest the second solution as it corresponds better to the logic of presentation of the views (table view with the arrow accessory etc ...).

So first the entry point of the immersioni storyboard should be the ListaDiveTableViewController and not a navigation controller. It will be presented in the stack and it will have access to the reveal view controller instance. Just set a background color to the navigation bar to see the back button and the right bar item too.

After, in immersioni storyboard too, the segueDiveDettaglio segue should point to the DiveTableViewController and not to a navigation controller. So you have also to change your code in ListaDiveTableViewController.swift:

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

        if  segue.identifier == "segueDiveDettaglio"
        {
            /*
            let destination = segue.destination as! UINavigationController
            let guest = destination.topViewController as! DiveTableViewController
            */
            let guest = segue.destination as! DiveTableViewController
            let indexPath = self.tableView.indexPath(for: sender as! UITableViewCell)!
            guest.idDivePass = self.dive[indexPath.row].idDive
        }
    }

Finally, in PostViewController, replace push with set (because push present a new child view controller only if the right menu is open, you should use also a popToRootViewController to go back to the first controller of the navigation stack).

    @IBAction func vaiBtn(_ sender: Any) {
        let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let desController = mainStoryboard.instantiateViewController(withIdentifier: "VetrinaTableViewController") as! VetrinaTableViewController
        let newFrontViewController = UINavigationController.init(rootViewController:desController)
        print("reveal: \(String(describing: revealViewController()))")
        //revealViewController()?.pushMainViewController(newFrontViewController, animated: true)
        revealViewController()?.setMainViewController(newFrontViewController, animated: true)
    }

There is a lot of views in your application and I was also busy by the way, so the answer is a bit late. But your application will be great.

I hope this answer will help you.

FedericoSub commented 5 years ago

Ok thanks a lot I'll try with your suggestion...

iDevelopper commented 5 years ago

Welcome, let me know if you need, keep me informed.