Creating a UIButton that pages back to the previous page - ios

I'm sure this is super simple but I'm new to iOS development so I must be missing something.
In xcode I have a like 5 page app and I can navigate forward no problem... To navigate backwards shouldn't I be able to create the button, then simply control and drag to the page I want it to go back to?

Yes. This is called an unwind segue. If using swift, this is how to do it.
Write this code in the view controller file that you want to go back to:
#IBAction func unwindToPreviousScreen(segue: UIStoryboardSegue) {
}
After writing this code, go to the storyboard, and go to view controller that is the one you don't want to go back to, and control-drag from the view controller to the exit icon in the tab bar of the view controller (far right icon). Make sure you have clicked on the view controller.
It doesn't have to be unwindToPreviousScreen, it can be whatever you like, but be sure to keep the unwindTo part intact.
Apologies if you are using a different language, I am just a swift person.

Related

Why does View Controller Shift in Storyboard on Button Segue

I am new to IOS App development and have a question. I'm trying to segue from one view controller to another. However, it seems that every time I ctrl+drag from the options button to the adjacent view controller and choose the 'show' option, the view controller "shifts" down(bottom picture). Why does that happen and if it is not the correct behavior, how can I do it right? Thanks!
You need to set fullscreen style manually if select model style,
a fullscreen option did not show in Push type, you must use Navigation Controller if you want to set fullscreen for Push
https://i.stack.imgur.com/rg20Y.png
When you click on the segue(the line that connects view controllers) and open the Attribute Inspector in right panel, you will see the Kind is set to Present Modally. This means your view controller will popup on your current screen.
You can change the Kind to Push and it will start showing normally.
Also embed your controller in a navigation Controller
Option 2
If you dont want a navigation controller, you can also change the presentation to full screen.
If you're new to iOS
then I might suggest don't use show and don't use segue from storyboard
If you don't know the concept of navigation controller (push and pop methods), then have a look at it (You may not use show afterwards)
have a look at following link
Swift programmatically navigate to another view controller/scene

Xcode / Swift: How I implement a back button?

I just started with Xcode and Swift.
I try to build my first little App for iOS. But now I have the problem, that I don't know how to implement a the back button, so that i come back to the view before.
My Storyboard look like this:
When I open the A-Z view, I want to display the Back Arrow, which turn me back to the Item 2 view.
To open the A - Z view I connect the button "Medikamente A - Z" with the Navigation Controller.
When using storyboards the back button is usually implemented with unwind segue.
I usually like to follow raywenderlich toturials on UI related topics, like this - http://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2
It include a detailed example of how to implement back button in storyboards. Quoting from it -
Storyboards provide the ability to ‘go back’ with something called an unwind segue, which you’ll implement next.
There are three main steps:
1. Create an object for the user to select, usually a button.
2. Create an unwind method in the controller that you want to return to.
3. Hook up the method and the object in the storyboard.
When using UINavigationController, whenever you push to a new ViewController the back button will automatically appear, so you can jump back to the previous View Controller.
So it's works like:
UIViewController -> UIViewController -> UIViewController
A back button will appear on the last 2 so you can pop back the the previous ViewController.
You don't have to do any additional coding for the back button to appear, it'll do it on its own. I hope this clears it up. Let me know if you have any questions.
To implement a back button, your root view controller has to be a Navigation Controller.
The first view controller becomes the navigation root of the navigation controller.
If you want to present another view controller, you select a "Show Detail" relationship as the action for the button which should show the view controller. To do this, Ctrl-click and drag from the button to the destination view controller and select "Show Detail".
I had the same problem, even when on the storyboard the back button was visible at design time.
I deleted the segue, and recreated it with "Show" instead of "Show detail". Changing the segue to "Show" had no effect. I think this is a bug, so if you miss that back button delete and recreate the segue.

Unwind segue function with Back button

I'm trying to call function when i'm pressing default Back button (e.g. < Settings) in Navigation Controller.
At other situations i'm creating custom button, after i'm Ctrl+Dragging to red Exit button in XCode and pointing it to Selection segue.
Now i need to use default back button of navigation controller, but i can't set assign it to segue action because it's no back button in Storyboard view (but it exists in Simulator).
Simulator:
XCode:
I can create custom button in navigation contoller and assign it so custom unwind segue, but that button will be ugly without "< " symbol.
I've found some answers at stackoverflow, but they all are written in Objective-C :(.
You can use a delegate method to accomplish what you are doing.
Here is a really thought out swift tutorial that deal with delegates and segues:
http://makeapppie.com/2014/07/05/using-delegates-and-segues-part-2-the-pizza-demo-app/
What you are asking, ability to catch the back button's action, isn't possible the way you describe it.
Most people would recommend creating a custom button, then use an unwind segue.
There are lots of tutorials on custom back buttons just in case you're new to swift, and the ugly part of the custom back button can be easily fixed by putting your own arrow there.
Also I found this previous asked question for future reference: Unwind segue from navigation back button in Swift
Actually I just assigned the unwind segue to the entire view controller (right click from the yellow view controller outlet and drag to the exit outlet then select the function). And it works great so far. No need custom button, no delegate.
In fact, in my project the child is supposed to call the different parent's function according to current caller view controller and simply using the same function name made my dreams come true.
This page helped me a lot: http://spin.atomicobject.com/2014/12/01/program-ios-unwind-segue/

Proper way to segue between two simple View Controllers in iOS 7

I'm mainly from a C# background, so the workflow for iOS is a bit unusual for me, at least for now.
I was having a problem having simple segue from a main menu, to a another menu/work area, and then with the ability to go back to the main menu.
For a test, apparently I did something wrong.
I didn't write any code for this test to exhibit the problem.
What I did was just,
create a new single-view app
drag an additional view controller onto the work area
drag the start arrow to the new view controller (so it becomes the initial view, same thing as checking the checkbox to set it as the initial view)
added a button to each view controller
Ctrl + clicked and dragged the buttons to the opposing view
for the segue type, I chose "replace"
now the program crashes if I hit the second button to go back to the "main menu" (green view controller in this example)
So what am I doing wrong? Do I need to add some form of delegate or something?
I did find this, though it present fewer segue options in the tutorial than what I have.
https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html
These are the options I have when I Ctrl + Click from a button to another view
-Push
-Modal
-PopOver
-Custom
-Replace
"Have you embedded a navigation controller? You need to go to editor->embed in-> Navigation Controller. You need a navigation controller for push segue. – Kaushal Bisht"
This solved it for me. Now I'm just going to work on replacing the navigation bar with custom UI controls.
Thanks everyone! :)

Page-based App, UINavigation Controller, Similar to iOS Calendar

I want to do use the Apple template for a Page-based App (Xcode 4.4.1, iOS 5) and then be able to "push" pages from the page view...
Create a Page-based App
Add a button to Data View -> view -> view (The nested view)
Add a "Push" segue to a new Controller/View
Expect when the button is pressed that it will "Push" to the new view.
But it doesn't, and I don't know how to make it happen. I assume I need a UINavigationController somewhere, but I'm not sure where and how to insert it.
Note: I can use a modal segue which does what is expected, but not a push segue.
Thanks.
I found the answer, and it was one of the two obvious choices. I added a navigation controller in front of the RootViewController.
I think I missed it originally because Xcode keep crashing so I assumed it wasn't going to work.

Resources