Combining Navigation with Controller to PageViewController - ios

I am using a PageViewController to manage a series of viewControllers which all use a tableview. As the following picture depicts the PageViewController is a container controller for the PageContentViewControllers
After clicking on a tableCell I would like the app to navigate to a detailed view. From what I have read, the proper way to do this is by using a navigationController which is also a container controller.
Through storyboard I have tried putting the NavigationController at both the PageViewController and the PageContentViewController and neither seems to work correctly, I am not sure what other approach I am take.
What is the proper way to combine a PageViewController with a NavigationController if they are both container controllers?

Depending on how you want to structure your app:
Embed your PageViewController in a Navigation Controller (select the PageViewController in storyboard and choose Editor > Embed In > Navigation Controller)
Embed the new Navigation Controller in a Container View within a super controller.

Related

Different navigation item for each view in tab bar controller

The Problem
I'm relatively new to Swift and I'm trying to build an application that makes use of a UITabBarController.
What I'm trying to do is put a different navigation bar (or UINavigationItem) on each of the tabs in the UITabBarController.
For example, I want the UINavigationItem I set, with its bar button items, to appear on MyViewController instead of a back button to the previous view controller, such as shown on the image below.
The current layout on the Storyboard is as follows.
MyViewController on the sidebar:
What I've Tried
Someone suggested that I should embed each UIViewController (e.g. MyViewController) in a Navigation Controller. I've tried this and it doesn't work.
I've also tried to set the Top Bar to "None" in the Attributes tab of the options menu.
Thank you in advance for your help.
Here is how i did it,
UINavigationController -> UITabbarController
And then each "Tab" is in different Storyboard and every storyboard start with a "Navigation Controller". So yes every tab in different navigation controller this how you should do it.
Different storyboards because may be multiple people work on storyboard at same time.
Why TabbarController inside Navigationcontroller ?
I put the "TabbarController" inside "NavigationController" because some of the controllers i want them to be full screen, like hiding the "Tabbar" so for that i push them from main NavigationController.
//Out of context but may help you,
I have created an "Extension" of Navigation Controller to push a view controller on main navigation so that any of the tabbars (which are also inside navigation controllers) can easily use the extension to push any view controller if want to hide the tabbar.

How to make SWRevealViewController a child of another controller in swift

Hi I've a problem I tried to solve it by reading the docs but I couldn't.
I want to the tab bar controller to be the initial VC Not the SWRevealViewController.
The issue is that the slide out menu in side the app not the first vc.
So the question how to make the SWRC there?
Why could not you move your reveal view controller as a last controller in navigation queue and use your controller with "Item" menu as Sw_front? It should work.
As an alternative you can remove the whole reveal view controller from Storyboard and create it manually from your first view controller in navigation queue. And then push.
SWRevealViewController has a method called initWithRearViewController:frontViewController, and you can obtain Sw_rear and Sw_front view controllers with instantiateViewControllerWithIdentifier from Storyboard.
Then, when adding Item menu (manually) to navigation bar, you assign revealToggle: as action and your SWRevealViewController instance as target.
There are some variations of this approach, you can place your SWRevealViewController before the Navigation Controller in Storyboard and specify Navigation Controller as a Sw_front. Then you do not need to instantiate SWRevealViewController manually, but only "Item" menu.
Here could be also useful to removeGestureRecognizers from reveal view controller on viewWillAppearof intermediate view controller in navigation queue and then add back panGestureRecognizer and tapGestureRecognizer on viewWillAppear of the view controller with "Item" menu.
UPDATE
Here is the sample project of using SWRevealViewController in Swift with Tabbar.
I've just taken the sample project from http://www.appcoda.com/sidebar-menu-swift/ and adjusted a little bit.
And what I dislike about using SWRevealViewController with Storyboards is that each new ViewController to be shown, has its own Navigation Controller, but if it works for you, you can keep it.

Display extra view controller without removing the tab bar

My app has a menu and a UITabBarController. What I want to do is to display a view controller that belongs to my menu but not to the UITabBarController, However I don't want to remove the UITabBarController. I tried codes similar to the one below but they are removing the UITabBarController.
tabBarViewController.selectedViewController?.presentViewController(ExtraViewController, animated: true, completion: nil)
You should get UINavigationController of selected ViewController and then push view you want to present. Otherwise you are presenting modal view controller with presentViewController witch hides your UITabBarController view.
Im not at my computer right now, and cant post any code, but hope this helps.
Best way to do it is to use UINavigationController. You can create new one programmatically and put your menu controller as root.
And if you put this UINavigationController as one of views in UITabBarController then you can preform a code like:
[self.navigationController pushViewController:ExtraViewController animated:NO];
Also you can use storyboard to create your controllers hierarchy like that:
To do that select your menu controller and go to Xcode menu>Editor>Embed in>Navigation Controller and then Xcode menu>Editor>Embed in>Tab Bar Controller.

Going from NavigationController to TabBarController

So... I've got a ViewController that's being pushed onto a NavigationController. In interface builder I create a separate ViewController and Embed it into a TabBarController and it looks good in Interface Builder.
In my app, I'm trying to go from one of the ViewControllers in my NavigationView to the ViewController in the TabBarController. How would I do this the correct way? I can't just push the view onto the NavigationController, because the tab bar at the bottom won't show up.
Any help would be greatly appreciate.
I believe you're operating with the UINavigationController and UITabBarController in a backwards order to recommended best-practice.
Unless something has changed in the last year or two (which may have happened) the UINavigationController should never have a UITabBarController pushed onto it. If you are using a UITabBarController in your app, it should be the window.rootViewController, and the navigation controller being member of the UITabBarController's viewControllers array.
I'm trying to go from one of the ViewControllers in my NavigationView
to the ViewController in the TabBarController. How would I do this the
correct way?
In that structure, you'd assign your destination view controller as another element of the viewControllers array. Then, in my style, I'd send a NSNotification something like "LaunchOtherViewController" from your first view controller, and thus you have no need for the first view controller to know about the tab bar controller or second view controller. Then have some class that knows about the second view controller receive that notification, and update the selectedIndex of the UITabBarController to that of the second, destination view controller.
Hope that makes sense.
You need to push the TabBarController onto the view. You may need to set the selected view controller of the tab bar, but it's important the tab bar controller be actually pushed onto the navigation stack (or presented modally).

NavigationController inside TabBarController, or vice versa?

I apologize if this is simple or answered elsewhere, but I can't seem to find it.
I'm building a tabbed app in which some (but not all) tab views need navigation. Should I:
1) Use a UITabBarController root controller in which the navigation subviews are themselves UINavigationController instances.
2) Use a UINavigationController root controller, containing a TabBar instance, and hide the bar navigation when on a tab that doesn't need navigation services.
3) A totally different architecture.
?
If I understand your choices, you want to do #1. The view controllers that are connected to the tabs can be navigation controllers. In a storyboard, you can start with the tabbed application template, and delete the view controller that's given to you by default, drag in a UINavigationController, and reconnect it to the tabBarController with a relationship segue.

Resources