How can i define a NavigationController that embeds a ViewController? - ios

I have seen a project with the following storyboard:
http://www.disclafani.org/vc.png
I would like to know how it has been built the CustomerPagesViewController as NavigationController, i don't see a RootNavigationController for it.
In short terms ... how can i define a UINavigationController that embeds a ViewController?

When you drag and drop a navigation controller in storyboard, it will create two controllers (two scenes to be more precise): a navigationbar controller and a tableview controller that will be defined as your rootview controller. All you have to do is replace your tableview controller by your custom controller: it will be embedded in your navigation controller.
EDIT
Sorry I think i mislead you in my first answer: it doesn't look like you can simply replace one controller by another. If you want a custom view controller embedded in a navigation controller a better approach would be:
Drag and drop a view controller on storyboard
Reference your custom view controller by editing the custom class field in the identity inspector
Drag and drop a navigation controller on storyboard
select your custom view controller and select from editor the embed in option by choosing navigation controller: your navigation controller should now contains your view controller. You can deleted the tableview controller that was created when you drag and drop the navigation bar controller.

Related

How to connect a Navigation Controller in one storyboard to View Controllers in another storyboard?

Here is my Navigation controller that has one View Controller in the stack, but I have another storyboard with Viewcontrollers I want to add to the stack. I have the Views separated in order to better organize my Views and to have less views per Storyboard. How do I add Views from the referenced storyboard to the Navigation controller shown?
Right now I have the reference pointing to another Navigation controller in the second storyboard, but I wouldn't have a back arrow to the viewcontroller in the first Navigation Controller.
In the Storyboard A where you have a navigation controller add a Segue to Storyboard B (Settings) and make sure that you also write the View controller ID (MyViewControler) that you like from within Storyboard B in the Referenced ID
in Storyboard B (Settings) add a navigation controller and set the root view controller to the one that you like (MyViewControler) this navigation will be use only show the UI as it will be in the navigation controller from Storyboard A and will not be part of the navigation stack, This is because you add Referenced ID !!!

Why does embedding a View Controller in a Navigation Controller, then in a Tab Bar Controller attach the nav bar to the Tab Bar Controller?

Back when I first created the foundational layout for the app I'm currently working on in Storyboard, I did it in two steps:
Selected my View Controller and used Editor->Embed In->Navigation Controller.
Selected my View Controller again and used Editor->Embed In->Tab Bar Controller.
This was the resulting layout:
Question 1: Why do these steps create such an odd layout?
In this weird layout that seems to imply that the Navigation Controller is attached to the Tab Bar Controller as its parent, the only way I can get navigation items to display in the app (in the view controlled by the View Controller on the right) is by placing them in the nav bar of the Tab Bar Controller scene.
However, this creates various issues, including not being able to create an IBOutlet in my View Controller file for a custom view I drag into the title view slot in the Tab Bar Controller scene. Meanwhile, dragging anything into the navigation bar in the View Controller scene just makes it not appear in the app when it runs.
Question 2: How can I fix this layout so that I can control-drag from navigation items into my View Controller file? Or is everything actually correct, and I'm just trying to force something I shouldn't? (My intention here is to be able to set the custom title view's text in my View Controller code.)
Its obvious, if you want to embed MyViewController to NavigationController then you need to change your second step and need to embed NavigationController to Tab Bar Controller.
Selected MyViewController and used Editor->Embed In->Navigation Controller.
Selected NavigationController Embed with MyViewController and used Editor->Embed In->Tab Bar Controller.
It should look like this.
Note: You need to embed MyViewController to navigationController only if you want to perform push operation on this TabBarItem means with MyViewController other wise simply embed MyViewController to TabBarController no need to embed it with NavigationController.

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.

Segue-ing to Embedded view controller

I have have a view controller that is embedded in a UINavigationController and I want to segue to another view controller that is also embedded in a different UINavigationController. If I try to use a push segue, I get an error saying that I can't push a UINavigationController. However, I don't think using a modal segue is appropriate. How should I go about this?
How should I go about this?
You should use a single navigation controller.
the problem is that I want different bar button items for each view controller and they won't change
Each view controller can set up the bar buttons however it likes. Take a look at UINavigationItem. Each view controller has a navigation item, and the navigation item has various properties such as leftBarButtonItems and rightBarButtonItems that you can use to set the buttons.

SWRevealViewController hierarchy leading to black screen

Firstly, I would like to say that there are no errors with my code from a programming standpoint - it runs successfully, so a round of applause for that. However, the issue I am having is that when I run the application, it displays a black screen. I assume the issue has something to do with how I have set up the segues or something similar.
Hierarchy:
Reveal View Controller -> Table View
-> Navigation Controller -> Tab View Controller -> FirstViewController
Important To Note:
Reveal View Controller class is set to "SWRevealViewController"
Table View Controller class is not set.
Table View Controller segue ID set to 'sw_rear'
Navigation Controller class is not set <possibly the issue, but I cannot set the class to SWViewController as suggested by a thread online.>
Navigation Controller segue ID set to 'sw_front'
All other controllers have no set class.
I have discovered the solution. Hopefully others can learn from this.
When you create a project using a Tab Bar Controller as your base, an arrow will appear to the left of the Tab Bar Controller in the Storyboard. Moving that arrow to the Reveal View Controller (View Controller you set to the class of SWRevealViewController) lets Xcode know that you want to start your hierarchy from that object.
I had the same problem. What helped me resolving the issue was to remove the Navigation Controller that linked to the view (in my case was UItableViewController), and re-insert a new Navigation Controller (clicking the tableviewcontroller, Editor > Embed In > Navigation Controller).

Resources