Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavController issue and switching to normal VC #68

Closed
alpa99 opened this issue Aug 18, 2017 · 17 comments
Closed

NavController issue and switching to normal VC #68

alpa99 opened this issue Aug 18, 2017 · 17 comments

Comments

@alpa99
Copy link

alpa99 commented Aug 18, 2017

Hello, in the picture below you can see how I build up the drawer content in the storyboard. What you can't see is that the pulleyVC is also embed in a tabbarcontroller.

bildschirmfoto 2017-08-19 um 00 26 55

I have now 2 problems with the results of this, I don't know how to fix.

  1. When i embed the DrawerContentVC in a NavigationController, the collapsedDrawerHight function doesn't work anymore. I did set the value for the collapsed Hight to 120. Without the NavController it works like it should.
  2. By clicking a cell from the Table View of the DrawerContentVC the second View (BarDetailVC) is opening up inside the drawer. But I want the other VC to be not presented inside the pulleyVC but as a normal View. At the same time it's important that the tabbar at the bottom doesn't disappear when going to the second VC.
@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

I have one more question I d like to ask here.
My PrimaryContentVC contains a map and this map contains annotations. When the annotation view opens there is a detail button. I want by pressing this button to open the drawer vc in a partially revealed position. What do I have to write where ? Haha
Im sorry for this kind of question but its my first ever project :)

@amyleecodes
Copy link
Contributor

Apologies that I was just now able to get to this.

  1. That's expected. When you embed your Drawer Content VC in a navigation controller, and then assign the navigation controller as the drawer content in Pulley, the navigation controller is the drawer content VC from Pulley's point of view. You'll need to implement the delegate methods in a custom subclass of UINavigationController. You can write your subclass to forward these to the currently visible view controller in the navigation stack if you'd like, but that's an implementation detail left up to you.

  2. As you've seen a navigation push from inside the drawer will cause the new view controller to remain in the drawer. This is how navigation controllers work, which is expected. Any form of Modal presentation will hide the tabbar, so I'm assuming you want to do a navigation push. In that case, you want your view controller structure to look like this: Window.rootViewController -> UITabbarController -> UINavigationController -> Pulley -> Drawer / main content. This makes it so that when you 'push' to a new view controller, Pulley disappears. This will allow your tabbar to remain on top.

And for your last question:

You want to call 'setDrawerPosition' on the Pulley VC when you want to do this. If your view controllers have a reference to Pulley, you can invoke it on that. If you don't have a reference, you can obtain a reference to Pulley from within your drawer view controller or main content view controller (assuming they're directly in Pulley, no navigation / etc in the middle) by doing this: (parent as? PulleyViewController).setDrawerPosition(...).

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

Thanks for your help. It all worked out.

But I did explain the second problem wrongly sorry. I changed the view controller structure just like you said and the BarDetailVC appears just like I told you I want to. But is it possible to make the BarDetailVC to still remain inside the drawer but the next upcoming view to be not inside the drawer ? Do I have to use the setDrawerContentViewController Method inside a prepare for segue func ? How do I have to use it if ?

@amyleecodes
Copy link
Contributor

You can put a navigation controller as the drawer content VC, if you want, and do it that way. But, you'll need to find a way to route pushes back to the navigation controller containing Pulley VC for when you don't want to show it in the drawer.

You can also use setDrawerContentViewController, which would be easier. If you want to use this method, you'll need to manually create your view controller instance and then pass it to that method.

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

You can also use setDrawerContentViewController, which would be easier. If you want to use this method, you'll need to manually create your view controller instance and then pass it to that method.<

yes I think thats the best option hence BarDetailVC is the only additional VC i want to present inside the drawer. But do I have to write it inside the DrawerContentVC class or the BarDetailVC class ? If its inside DrawerContentVC do I have to put it inside a prepare for segue class that it doesn't get called to early ?

@amyleecodes
Copy link
Contributor

Your drawer content vc would call it, and pass it the bar detail VC instance. If you need to go 'back', you'd do the opposite.

You can't do it as a segue, so you'll need to do this in code.

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

bildschirmfoto 2017-08-21 um 23 33 33

I have inserted these lines inside the DrawerContentVC class but didn't change anything at all.

@amyleecodes
Copy link
Contributor

You don't want to implement that method, instead you want to call it on the Pulley vc.

So, wherever you want this to happen (didSelectRow, or a button press action, etc.) try this (assuming your drawer content VC isn't in a navigation controller):

 let detailVC = BarDetailVC()
 (parent as? PulleyViewController)?.setDrawerContentViewController(detailVC, animated: true)

Note: If your view controller is loaded from a Storyboard or xib file, make sure you instantiate it the correct way...if that's the case, just loading it with the default initializer like that probably won't work.

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

Note: If your view controller is loaded from a Storyboard or xib file, make sure you instantiate it the correct way...if that's the case, just loading it with the default initializer like that probably won't work.

yes i had to instantiate it. :)
But now the BarDetailVC doesn't have the navigation bar at top...
That means no Back button in the top left corner... what am i doing wrong ?

I made the Navigationbar hidden for the DrawerContentVC but for the BarDetailVC i called
self.navigationController?.setNavigationBarHidden(false, animated: true)
inside the viewWillAppear function

@amyleecodes
Copy link
Contributor

That only shows if your view controller is pushed in a navigation controller. Since you're directly setting the drawer content VC of Pulley (not pushing it in a navigation controller) you won't have a back button provided for you. You'll need to work with a navigation controller as your drawer view controller and push within that, or add your own back button in your Detail VC.

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

Ok i got it thanks for all the help.
I think adding just an own back button should be enough here :)

Thanks !

@alpa99 alpa99 closed this as completed Aug 21, 2017
@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

bildschirmfoto 2017-08-22 um 00 17 18

Im sorry but I had to reopen this because I tried to add my own back button doing it like i did before but when i test it the app crashes. Shouldn't it work backwards the same way ?

@alpa99 alpa99 reopened this Aug 21, 2017
@amyleecodes
Copy link
Contributor

It should work the same. What error do you get when it crashes?

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

Well its a really long text inside the console...
I think these lines might be helpful

ERROR!!
2017-08-22 00:11:53.708 testapp[66270:2482664] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMetadataOutput setMetadataObjectTypes:] Unsupported type found - use -availableMetadataObjectTypes'
*** First throw call stack:

But the AVCaptureMetadataOutput method has nothing to do with these VCs its part of the QRScanner from the other tab. I don't know why this is written there

@amyleecodes
Copy link
Contributor

It sounds like your Storyboard instantiation line is instantiating your QRScanner, somehow / somewhere.

@alpa99
Copy link
Author

alpa99 commented Aug 21, 2017

Well i deleted everything and just repeated and now it works thank you anyway 👍
You are doing great work
I appreciate it a lot !

@amyleecodes
Copy link
Contributor

Thanks! Glad it worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants