iOS Detect unwind segue from push segue - ios

I need to detect an unwind segue from a child to a parent view controller. I know it is possible to do this if I have a button that initiates to unwind segue, but is there a way to detect it if I just use the standard back button that is created automatically
#IBAction func unwind(segue:UIStoryboardSegue) {
println("segue did unwind")
}
I have tried by putting this into the parent view controller, and then connected (ctrl+drag) from the child view controller to exit. But this doesn't call the above method

When You want to transition to the parent screen using the Back button, do to control-drag from the button to the parent VC. Control-Drag from the button to the Exit present on the top of VC. then select your unwind segue from the list.
Hope this helps. :)

Related

performSegue and go back to View - content destroyed

I am performing a segue to open another ViewController, afterwards I go back to the initial ViewController also via performSegue.
If I am doing this, all the values in the initial ViewController (e.g. the image in the UIImageView) are destroyed.
Do I need to save everything before I perform a Segue, or am I doing something completely wrong?
Thanks!
EDIT:
This is what I would like to achieve, if I press the menu button on my "HomeVC", the tableView of the SWRevealViewController pops out from the left side. If I press a cell, I get with segue push, to another UINavigationController. From this Controller I would like to go back to the "HomeVC".
Here is a screenshot.
You do it wrong. Performing a segue will create a brand new controller from the segue's destination and present/show it.
If you want to go back, you shouldn't perform another segue. Instead, you must dismiss() it if you presented the newController modally or pop() it if you show/push it.
This tutorial may help

How can i create a segue programatically?

I made a segue in order to pass data. When i click the button, it does the segue. I want to manage it manually with code, for example i want an error alert to be shown, before it moves into the next view controller. I use the code below, but when i tap the button, it presents the next controller right after.
I tried this:
performSegueWithIdentifier("mysegue", sender: nil)
You can't create a segue programmatically. You can invoke one programmatically however. As Paul says, remove the segue from your button and control-drag a segue from the source view controller to the destination you controller. Give it a unique identifier. Then you can invoke the segue in code with a call to performSegueWithIdentifier

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

Why UIBarButtonItem doesn't call IBAction before segue?

My question is very similar to : Swift: Make button trigger segue to new scene
The issue is:
I have a view controller, with a button that causes another view controller to appear modally.
I have Ctrl+Click from the button to the second View Controller, and created the segue in IB.
Then I Ctrl+Click from the button again to the source code of the view controller to create an IBAction method.
I assumed that the button will do two things now: a) call the IBAction method , and b) perform the segue.
What happens is only the segue for some reason.
When I delete the segue, or remove the call to the view controller from IB, then the IBAction is called, but Xcode tells me that the second view controller is not reachable now.
I want to be able to present an ActionSheet to the user and then be able to performSegue to the second view controller, based on what the user selected from the action sheet.
I know I can programatically call performSegue but that requires the creation of the segue and attaching it to a physical button in IB, which defeats the purpose of not calling the IBAction that button may already have.
If I want to do some additional steps before calling the segue I usually attach an IBAction to the UIButton and call the perform segue from within this, in the code. You can add a segue to the storyboard and give it an ID, without having to connect it to a button. You do this by control-clicking on the viewcontroller and drag to the next viewcontroller in the storyboard.
Connecting a segue from storyboard will automatically always perform the segue. You can do any preparation for transitioning to the new view controller in the prepareForSegue method.
If there is some logic that comes before, like a user selecting something from the action sheet, just use the IBAction and then perform the segue with performSegueWithIdentifier based on the user selection. However, you do not have to create another button, just ctrl+drag from one view controller to another and give the segue an identifier.

I want to pop from viewContoller to parent viewController with out code

I want to pop from childviewContoller to parentviewController in storyboard with out write any code in file with the help segue.
Thank You in Advance.
I would suggest having a button on your child view (potentially in a nav bar or anywhere else on the page). I your storyboard, control drag from the button on the child view, to the parent view. In the pop up, choose your action segue (standard slide in slide out would be the Show segue).
If you choose present modally as your segue, then you can change the Transition on the left to not animate. This give the segue a blunt but removal feel for the child segue.
Hope this helped

Resources