UIBarButton missing in DetailViewController - ios

Workflow design:
Swift 4.0, Xcode 9.2
The "Item" UIBarButton is missing when I run the below application. It is visible in storyboard though. Here's what I did:
Created a Master-Detail app from scratch
Embedded a TabBarController in the detail view
Removed the Segue from MasterViewController into NavigationController of the DetailViewController
Added a UIBarButton by dragging a UIBarButton into the first Tab view formed from the DetailViewController

Cocoa doesn't handle embedding a tabbar controller inside a navigation controller well (explained e.g. here).
You'll have to reverse the containment: Try to embed the detail VC in a navigation controller, and the navigation controller inside the tabbar controller, like this:
TabVC -> NavC -> DetailVC
For every additional tab you'll have to add a navigation controller. This way every tab can have it's own bar button items.

Related

Using storyboard references with UINavigationController

I have the following hierarchy in my app: UITabBarController to many UINavigationControllers. Each navigation controller has a UIViewController.
I’ve split this up so that each UITabBarController’s child view controller is linked via a storyboard reference. In each of these references there’s a UINavigationController as the initial view controller.
Again some of these other storyboard references are split up too, where one of the UINavigationController’s child view controllers also uses a storyboard reference.
These UINavigationController’s child view controllers in the new storyboards do not carry across the UINavigationController style. Unlike the UITabBarController which does take across the UITabBarItem and shows them in the UINavigationController.
Is there anything I can do to see the navigation item of these UINavigationControllers so I can add bar button items in IB?
It's straight forward really; just go to Editor > Embed In > Navigation Controller and embed your view controller in a UINavigationController. You can then select the UIBarButton items under the Object Library in xCode, drag and drop them to the navigation bar on your View Controller and voila!
You can then delete the UINavigationController when done with adding the UIBarButton items to your VC; those bar button items will still be referenced and shown in the final product when you run it.
In Storyboard go to the Attributes Inspector for the Controller you wish to add the navigation bar and click on top bar drop down instead of it saying 'inferred' click on 'Translucent Navigation Bar'

Maintaining TabBar when performing Segue in the tab item

I have a tabbed application running with 4 tabbed items.
Each tabbed item has its own view controller - controller1, controller2, controller3 and controller4. I can transition to anyone of them without problems.
I now have a new view controller newView. I perform a segue from controller2 to newView. Problem is, when I perform the segue, the TabBar disappears in newView.
Also, if I segue back, I don't see the tab bar in controller2 either.
How do I go about this in Swift. Thanks.
You should wrap each UIViewController (controller1, controller2, controller3 and controller4) in its own UINavigationController (in the storyboard you will find the option in Editor > Embed in).
Each of the four navigation controllers should in turn become tabs in your UITabBarController.
The transition from controller2 to newView will be within its navigation controller, which is enclosed in the tab bar controller and therefore the tab bar controller will not be dismissed.

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.

swrevealviewcontroller navigation item and bar button missing

hello I have implemented SWRevealViewController in my swift app. The problem I am having is If I set SWRevealViewController as my initial ViewController all works fine. But If I launch this controller through code
let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("swrevealviewcontroller") as UIViewController)
self.navigationController?.presentViewController(nav, animated: true, completion: nil)
the navigation Title and barButtonIcon Disappears which is in my case is a hamburger menu icon.
SWRevealViewController is connected to the HomeViewController. and I am initiating SWRevealViewController when user clicks the login Button.
If you need more information regarding the storyboard screenshot let me know. I'll upload here.
Updated:
storyboard
navigation controller's navigation bar will only show up for view controllers that are contained by that navigation controller. Here, you're presenting a modal view. It's not contained by the navigation controller.
If you want the navigation bar to continue to appear:
If it's purely a matter of style, put a navigation bar on the modal scene you're presenting in the interface builder.
If you need to modally present a view that should be contained in a navigation controller, then you need to present a navigation controller--not a view controller.
Finally, if the view you're presenting is intended to be part of the navigation controller's navigation stack, then you need to present it with a push, not a modal segue.
Update
Do like simple ,
and call the perform segue as
[self performSegueWithIdentifier:#"main" sender:self];
I solved my problem by pointing Navigation Controller first and Tab Bar Controller second. Please, see the picture below.
Hope this help!..Thanks...

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.

Resources