Closed FedericoSub closed 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)
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
This is in Immersioni storyboard where I select my dive number for display the detail
this is dive detail DiveTableViewController
from DiveTableViewController I go to PostViewController, this is PostViewController where if I push button "Pubblica in Vetrina" I should return to VetrinaTableViewController
Hum... Can you upload the whole project please?
It's 140MB so this is a link in Dropbox
https://www.dropbox.com/s/6kpeh2i6eu2x1tr/CSMApp.zip?dl=0
Thanks
Got it. I have a look.
Sorry I do not find how to go to this view!
logbook > Immersioni > #3 > Pubblica (button at the end) > Pubblica in Vetrina
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
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.
Ok thanks a lot I'll try with your suggestion...
Welcome, let me know if you need, keep me informed.
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 {
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() {
Thanks in advance. Federico