Adding a Back Button on A Table View Controller - ios

I am interested in implementing a back button to segue to a previous view controller. I have tried to embed a navigation bar onto the the top of the table view controller but the issue is when I do segue back to the first view controller, by default, Xcode keeps the navigation bar with a back button to go back to the table view controller. Is there a simpler way to implement a segue to go back to the first VC without the navigation bar remaining?

I'm not too sure if this works, but embed your view controllers including the first one inside the navigation controller. That would make all your view controllers with navigation bar above.
On the main view controller (the one you do not want to have the navigation bar), add the line of code inside your viewDidLoad method.
Swift 3:
self.navigationController?.navigationBar.isHidden = true

I found an easy way. On your TableViewController, drag a UIview to the top of the view controller and itll let you insert the view. From there just add your back button

Just assign your "Back" UIBarButtonItem to this method and it should work.
#IBAction func backButtonPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}

Sounds like a few problems
1) How are you navigating from the first view controller? Is it with Show (Push) if not, you are replacing the first view controller in your stack.
2) Based on your problem, make sure your first view controller is not embedded in a navigation controller
3) As Dylan mentioned, you need to hook your back button to remove the current view controller to return to the first one
4) Extension of (3), how are you segueing back to the first view controller? If you are explicitly navigating to first view controller with your back button handler, it's not actually going back but rather forward and keep the navigation bar.

Related

Navigation bar back button is not showing?

I am not getting back button after pushing to next controller through segue
it is just like making a connection between controllers through segue
there is no code included. it is happening in storyboard
- First:
You should make the source view controller (not destination) as rootViewController of the navigation view controller. You probably set the segue as push instead of that.
- Second:
Make sure you don't set the back button item manually anywhere.

Multiple Navigation Controllers with Back Buttons in Swift

I'm making an application that has:
Navigation Controller -> View Controller -> Navigation Controller -> View Controller -> Navigation Controller -> View Controller.
This is making it so that there's no back button on the second view controller, only the third one, and I can't get it to appear. I'm fairly new to iOS and simply want to have a path of view controllers that the user can navigate down and back. Is there a way to add the back button to the second view controller's nav bar? Is there a better way to do this? Is it problematic to just create buttons at the top of views that perform segues?
I found some Objective-C solutions but couldn't find anything in Swift. Thanks for your help!
Remove all the navigation controllers except the first one.Your app must be like this..
Navigation Controller -> View Controller -> View Controller -> View
Controller.
Call segue to move to the other controller .. Just dismiss your controller if you have modally showed them on back button pressed or pop them from
navigationController
if you have pushed them.
Now for Back, you can do it in multiple ways. One of them is, add a view on the top of your controller, add a button on it and implement an action when someone taped it..
I hope you will got that ...

Swift Using a Back Button on Two View Controllers

My second view controller is a table view controller. I wish to segue to a first view controller with a back button. I have tried using Editor>Embed In>Navigation Controller. It places a navigation bar on the top where I can place an Item (Back button) on it, and after segueing it back to my first view controller, it becomes very screwy (it shows two navigation bars on top of each other). Is there a better/easier way to move back to my first view controller?
if u want to use navigation controller to manage ur push&pop stuff, just make sure:
navigation controller is ur initial view controller
ur first view controller is the root view controller of navigation controller
set an unique identifier to second view controller
leave ur second view controller alone without any link to other vc
like this
then push like this
let secondVC = (self.storyboard?.instantiateViewControllerWithIdentifier("identifier"))! as! urVC
secondVC.title = "second view controller"
self.navigationController?.pushViewController(secondVC, animated: true)
and pop like this
self.navigationController?.popViewControllerAnimated(true)
alternatively, u can use unwind segue following this tutorial

How to Give Button Exit Functionality in iOS

I am designing two pages, one followed by the other, in Xcode 7. Let's call them the first and second view controllers. From a button in the first view controller, with a modal segue, the second view controller shows up. I want to add a button to second view controller so that when I hit that button, I can simply exit from the second and back to the first view controller.
I know this feature can be done by navigation controller with putting cancel button to the navigation bar on second view controller which I don't want to. I want specifically a button to have that functionality.
I thought of calling the first view controller with code when the button is tapped, but it sounds me like a bad coding. So, I would like to learn what is a good way of achieving this.
Thanks,
Add method to the second view controller:
#IBAction func exitButtonPressed(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil);
}
Next add button to the second view controller in interface builder and connect button's action to this method.
use Unwind Segues
Unwind Segues give you a way to “unwind” the navigation stack and specify a destination to go back to.
for sample tutorial1, tutorial2

navigation Done item not working

in the top view of my view controller (the last table view controller) has an add navigation item. i added a view controller object from the objects library and i ctrl + dragged from the plus button to the view controller. i tried the app and it works fine but i can't go back to the previous controller when i reach the last controller. since the last controller connected (by segue) to the plus button, i can't have a navigation bar on top. so i added one and added an navigation item called it Done. i created an IBAction method in the class that the last controller subclasses which have the following code:
[self.navigationController popNavigationControllerAnimated:YES];
However, when i run the app and press the Done button to go back, it doesn't work although i feel like what i did is totally legal.
If you would have made the final view controller segue a Push segue, you'd still have the navigation bar with a back button. It makes sense since you're adding a record that you'd want a modal view.
You can dismiss the current modal view with the following code:
[self dismissViewControllerAnimated:YES completion:nil];
Generally, you should use delegation and dismiss it from the presenting view controller. However, I think it's fine to dismiss yourself if you're using storyboards, segues, and ARC.
Did you create a Bar Button Item and assigned its 'selector' callback?

Resources