Closed Dbigshooter closed 8 years ago
Yes subclass SWRevealViewController and set the delegate to this subclass. Otherwise, see also https://github.com/iDevelopper/PBRevealViewController as SW is not maintained,anymore!
Thanks! Could you provide an example for SWRevealViewController? I am having trouble getting a hold of my MenuViewController, when I press the UIItemBarButton on my MapViewController, which is the sw_front. I tried to do this, however it didn't work.
func test() {
self.revealViewController().revealToggle(self)
if let viewControllers = self.view.window?.rootViewController?.childViewControllers {
for viewController in viewControllers {
// some process
print(viewController)
if viewController.isKindOfClass(MenuViewController) {
print("yes it is")
let c = viewControllers as! MenuViewController
c.delegate = self
}
}
}
}
Do you have guide to how to use PBRevealViewController in Swift?
The class is documented in PBTevealViewController.h and on cocoapods. Use it as SWRevealViewController. On the github repo there is 2 examples written in Swift. Just use pb_left, pb_main and pb_right instead of sw_rear, sw_front and sw_right.
For your problem the rear view controller is: revealViewController().rearViewController. If it is embedded in a navigation controller, the MenuViewController is the topViewController of the navigation controller.
But what is for the MenuViewController's delegate?
My hierarchy looks like this:
SWRevealViewController --- sw_rear ---> MenuViewController SWRevealViewController --- sw_front ---> MapViewController
When I click a button in the menu, I want to show something on the map in the MapViewController, hence the delegate.
You don't need a delegate to. In your MenuViewController, have you retained a reference to your MapViewController?
No, how would I do that?
Can you show a screenshot of your app?
Of the storyboard?
If you don't have a reference for your MapViewController, a new instance is created each time you open it from the menu?
The only thing I do is this:
self.revealViewController().revealToggle(self)
You have only one front view controller?
Yes the storyboard.
Initially, yes. You can navigate to other front view's using the menu, but some of the menupoints are meant to manipulate the current viewcontroller you're opening the menu from.
Then when you navigate to others from view and come back to map view, the map reloads.
Yes.
Oh, so you can just do this:
let navController = self.revealViewController().frontViewController as? UINavigationController
mapViewController1 = navController!.topViewController as? MapViewController
And it'll give you the sw_front, meaning the viewcontroller you came from?
You are in my sample? In MenuTableViewController?
mapViewController1 is the reference to the MapViewController instance, you can use it directly.
Yea, I am. That was exactly what I was looking for, finding a way to get a hold of the instance of mapViewController, so I can do thing with the map inside the controller by clicking on one of the menu points.
Then, it is OK?
Yea, perfect! Thank you so much!
A last question, when I click the menu item which do stuff on the map, can I make it go back to the map before starting the thing? Since it's a webservice call which can take some time.
Where is called the request?
It is called in the MapViewController, so I want the menu item to show the mapView and then request.
On button tap:
if the MapViewController is embedded in a navigation controller: let navController = UINavigationController(rootViewController: mapViewController1!) revealViewController().pushFrontViewController(navController, animated:true) else: revealViewController().pushFrontViewController(mapViewController1, animated:true) and call the request function: mapViewController1.request()
I did the same with a marker (added Add a marker in menu):
Thanks! Is it done the same way in PBRevealViewController?
Great! Yes. And you can have the left view (menu) above or below the main view.
Great! Thanks, much appreciated!
I just have a last question, when I push the map back, and add the pins, they layout I've done, another color on navigationBar is just white, and not the color I want, how come?
I don't understand your question. In your app?
Nevermind, I figured it out. I had to call the function that setup the layout in viewWillLayoutSubviews, since the viewDidLoad doesn't get called. Is it possible to show on the menu, which menu item I'm current on? If I called the menu from the mapViewController, I could show a grey overlay on the map menu point?
I think it is in your storyboard's constraints for the mapView.
Can I somehow know which viewController which called the menu?
This is the front view controller.
revealViewController().frontViewController
You can test that with the delegate function: (willMove or didMoveToPosition)
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
if position == FrontViewPosition.Right { // Menu will open
... // Test which front view controller will open the menu
Add this to my sample: In RevealViewController.swift:
func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition) {
if position == FrontViewPosition.Right {
var controller = revealController.frontViewController
if controller is UINavigationController {
let nc = controller as! UINavigationController
controller = nc.topViewController
}
print(controller)
}
}
Is your menu a table view controller? I did not see that you edited a comment above:
"Is it possible to show on the menu, which menu item I'm current on? If I called the menu from the mapViewController, I could show a grey overlay on the map menu point?"
Yea it is.
I was wondering, can I use SWRevealViewController for my left menu, and PBRevealViewController for my right?
I don't think so! But why use both.
For the table view controller, in viewDidLoad:
// Uncomment the following line to preserve selection between presentations
//self.clearsSelectionOnViewWillAppear = false
I want the left menu to be animated like SWRevealViewController does, and the right like the other.
PBRevealViewController can animates like SW (PBRevealToggleAnimationTypeSpring) and you can provide your custom animation controller too. Did you try the samples?
Oh perfect, I didn't even notice ;o)
I'll try the samples and get back.
Then in a new project?
I'm now trying to use PBRevealViewController, but I get a nil here. In the same project as before:
let navController = self.revealViewController().frontViewController as? UINavigationController
And if I try to run the examples I get that there is no podfile and such, 3 errors.
Can PBRevealViewController animate just like SWRevealViewController? Like pushing the main view away and not showing above it?
Where? In the main view controller? Is the view on the screen?
In the MenuViewController, it crashes since it is nil. But before we continue: Can PBRevealViewController animate just like SWRevealViewController? Like pushing the main view away and not showing above it?
Yes.
Cool, do I need to subclass it and make my own controller, or can it be done in another way?
And I use static cells in my menu, how can I just change mainview when I click at them?
If you want the main view controller to the right, and below, set leftPresentViewOnTop = false.
Like this?
Yea, but without the shadow ;o)
I cannot get the push to work. On my static cell I've made a custom segue with PBRevealViewControllerSeguePushController, but it doesn't work.
Hi there!
My problem seems fairly simple, but I just can't figure out how to solve it. When my MenuViewController is showing, it's the rear one, I need to set a delegate in the MenuViewController so I can modify the content in the ViewController I came from. For instance I have a button in the MenuViewController which is meant to modify the map in the ViewController I am showing the MenuViewController from. Any suggestions? Really appreciated!