Uinavigationcontroller Without Navigation Bar

UINavigationController without navigation bar?

You should be able to do the following:

self.navigationController.navigationBar.isHidden = true //Swift 5

where self.navigationController is (obviously) an instance of UINavigationController. Seems to work for me, but I only briefly tested it before posting this.

How to hide a navigation bar from first ViewController in Swift?

If you know that all other views should have the bar visible, you could use viewWillDisappear to set it to visible again.

In Swift:

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}

Add a navigation bar to a view without a navigation controller

While there are several smart ways to answer your question. I just solved it programmatically and wrote the following code in my viewWillAppear (note - viewDidLoad is also okay, but not suggested) -


-(void) viewWillAppear:(BOOL)animated {

UINavigationBar *myNav = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[UINavigationBar appearance].barTintColor = [UIColor lightGrayColor];
[self.view addSubview:myNav];

UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:nil];

UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered
target:self action:nil];

UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
navigItem.rightBarButtonItem = doneItem;
navigItem.leftBarButtonItem = cancelItem;
myNav.items = [NSArray arrayWithObjects: navigItem,nil];

[UIBarButtonItem appearance].tintColor = [UIColor blueColor];
}

So, you have a white navigation bar with blue bar button items without a Navigation controller. Again, there are other ways to implement it in your case. Hope, this was helpful.

Output -

Sample Image

Update -

To add images -

UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,10,32,32)];
[myImage setImage:[UIImage imageNamed:@"image.png"]];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myImage];
[self.view addSubview:myImage];

Show back button without navigation view controller

You can't achieve navigation functionality without using UINavigationController. I mean you have to do all animation kind of stuff on your own, and I think that's not a good idea. Rather than that, you can use UINavigationController, and if you don't want to show navigationBar at some viewController, than do as follows for those view controllers.

override func viewWillApear() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
}

override func viewWillDisappear(animated: Bool) {
self.navigationController?.isNavigationBarHidden = false
}

Add Navigation Bar with title without Navigation controller on UITableViewController from Storyboard

In Storyboard, you can't add any other view at the same level of the TableView in TableViewController, so adding UINavigationBar won't work here.

You can show navigation bar using UINavigationController:

  1. In Storyboard first, select your Table View Controller.

  2. Then Open Editor menu, and select Embed In option, and choose Navigation Controller. You will get your navigation controller pointing to your tableview controller.

Swift - How to access Navigation Bar from another controller

You have a UINavigationController
whatever you push into this navigation you could access the navigation without passing it

self.navigationController

the NavigationBar is shared between all the controllers will be pushed into the navigation stack

the navigation item is only related to your controller

so if you added a navigation bar for A controller is a different navigation bar for the B controller even if both of them pushed to the same navigation controller

        self.navigationItem.leftBarButtonItem = .init(title: "Ate", style: .done)


Related Topics



Leave a reply



Submit