How to create a navigation stack of views in SwiftUI? - swiftui

In UIKit it is possible to create a navigation view controller with a stack of UViewControllers.
let nav = UINavigationController()
nav.viewControllers = [vc1, vc2, vc3]
How would you achieve same in SwiftUI?
There are navigation buttons that push a view but there is no navigation controller

Related

Prevent Navigation Bar from collapsing and being sticky when on scroll SwiftUI / UIKit

I would like the NavigationBar (from a SwiftUI NavigationView) to just stay large and scroll out whenever I scroll in a Pages ScrollView. Right now it is always collapsing and showing even on scroll in ".inline"-display mode. So when I try to completely hide it I also hide the large title I'd like to keep.
Is there a way to just let it stay large and just scroll out?
Any solution in SwiftUI or UIKit is appreciated as I can introspect from UIKit.
I especially don't want the NavigationBar to be hidden and rebuild by VStack or HStack as this causes loosing all Navigation Gestures like swiping back to the previous Navigation View and so...
Here is a basic codesnipped to recreate
struct TestTestView: View {
var body: some View {
NavigationView {
ScrollView() {
Color.green
.frame(height: 1000)
}
.navigationTitle("Test")
}
}
}

How to add a right button when specific UIViewController get loaded in Swift 3

I have two different UIStorboards and I am using a UINavigationController to load the pages.
I have a total of three UIViewControllers. Two of them are on the first UIStoryboard and the third one is on the second UIStoryboard.
1) Navigation controller
2) Main Controller
3) Value Screen Controller.
I want to add right button on navigation bar only when value screen controller get loaded. It should not be available on Main view controller.
I tried with this solution but not worked.
Each UIViewController has its own UINavigationItems. So you can just add this right button in your Value Screen Controller by adding this line:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: <#T##UIBarButtonSystemItem#>, target: <#T##Any?#>, action: <#T##Selector?#>)
You can place it in func viewDidLoad() if you want it to be place as soon as the UIViewController's view is loaded.

Navigation Bar Background Color Light with Swift 3

I add Navigation Bar in any view controller. But, I'm adding new CollectionView Controller in project. My problem is that I could not add Navigation Bar in Collection View Controller.
So I add Navigation Bar with code. I choose Top Bar- "Inferred" in Attributes Inspector. Here is the code.
//Add Navigation Bar
let height: CGFloat = 65
let navbar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height))
navbar.delegate = self
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green:49.0/255.0, blue:79.0/255.0, alpha:0.1)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
But, the Navigation Bar Background Color in Collection View Controller is a little bit dark than other view controller.
In other view controller, I drag and put navigation bar.
- Navigation Bar style --> Black
- Translucent --> not enabled
- Bar Tint Color --> #00314F
I don't know why Navigation Bar Background Color in Collection View Controller is light than in Collection View Controller.
Please help me how to match Navigation Bar Background Color in all view controller.
If it is not easy to do, is there any ways to add Navigation Bar in CollectionViewController without embedded in Navigation Controller and without code.
It is beacause of the Translucent property of NavigationBar. It gives an effect where the image color looks faded as if a layer has been put on the bar, hence the color looks a little and different. Set off the translucent property of navigation bar as shown below. You can write this code in any lifecycle methods.
self.navigationController?.navigationBar.isTranslucent = false
It is because of translucent i think. When the navigation bar is not translucent, view can't locate behind the navigation bar to show what it has. But when is translucent, view stays behind the navigation bar and with view's color, you see it darker.

UITabBar item did select is not working

i have two tab bar items with two different table view with navigation controllers.
by clicking on the tab1--- table1 is opening...Good. but when i did select on table1 it goes to the another view (table did select view)....every thing is good.
but the problem here is
when i am clicking on tab2 ----table 2 is opening....Good.
But again clicking on tab1------ it is not loading the table1....it is loading (table did select view) view. As the last time i left it there.
i want to open table1----on clicking on tab1......by programming.
help me
That is the expected behaviour if you are using the tab bar controller and the navigation controller in the item of the tab bar. User will expect the tab to retain the state of the view.
If you still want to enforce the app to go back to the root view controller of the navigation controller when user goes back to the tab, you can implement the UITabBarControllerDelegate tabBarController:didSelectViewController: method. What this delegate method does is:
Tells the delegate that the user selected an item in the tab bar.
Then call the method of UINavigationController called popToRootViewControllerAnimated: when user tap on the tab. This will help you to:
Pops all the view controllers on the stack except the root view
controller and updates the display.
For example:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if(viewController == yourNavigationController) {
UINavigationController *navigationController = (UINavigationController *)viewController;
[navigationController popToRootViewControllerAnimated:NO];
}
}

How to add a navigation bar to UITabBarController?

Im trying to add a navigation bar to all view controllers inside my tabbarcontroller. Do I add the nav bar to individual view controllers...
or
Is there another way?