Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit
This is a known issue with Xcode 6:
Unwind segue actions declared in Swift classes are not recognized by Interface Builder
In order to get around it you need to:
- Change
class MyViewController
to@objc(MyViewController) class MyViewController
Create an Objective-C header file with a category for MyViewController that redeclares the segue action.
@interface MyViewController (Workaround)
- (IBAction)unwindToMyViewController: (UIStoryboardSegue *)segue;
@endIn the storyboard, select the instance of MyViewController, clear its custom class, then
set it back to MyViewController.
After these steps you are able to connect buttons to the exit item again.
Xcode 6 Release Notes PDF, Page 10
Cannot Connect Storyboard Unwind Segue
You need to have an IBAction defined on a view controller that takes an argument of type "UIStoryboardSegue *".
Something like this:
@interface MyViewController
...
- (IBAction)unwindFromConfirmationForm:(UIStoryboardSegue *)segue {
}
...
@end
Swift 3 Version
@IBAction func unwindToViewController(segue: UIStoryboardSegue) {
//code
}
Provided by DoruChidean in https://stackoverflow.com/a/46199117/250190
Why is interface builder not showing my unwind segue?
To re-iterate: not only an Action for a Storyboard Unwind Segue has to be placed in the same source file as class
definition for an unwind-to (destination) View Controller (e.g., @IBAction func prepareForUnwind(segue: UIStoryboardSegue)
, detected as prepareForUnwind[With]Segue
in a "Presenting Segues" list), but also that View Controller cannot have ANY extensions in ANY secondary source files. You have to merge class
definition and all extensions into a single source file.
(As of Xcode 8.2.1.)
Cannot create Unwind Segue Xcode 11 Via Storyboard
It's still working... right-click or control + drag... but..
Before you can begin adding unwind segues in Interface Builder, you
must define at least one unwind action
exemple
@IBAction func unwindToMainMenu(sender: UIStoryboardSegue)
{
let sourceViewController = sender.source
// Pull any data from the view controller which initiated the unwind segue.
}
Unwind Segue in Xcode 6.1.1 with storyboard
Got it working. If you are presenting from a NavigationController or TabBarController(unsure about the TabBarController), you need to subclass the navigation controller and add the unwind segue to that. In storyboard don't forget to change the class of your navigation controller. My view hierarchy was NavController -> TableController -> DetailController. After adding method to custom NavBar class add it to the VC you want to RETURN to. You will then be able to ctrl-drag to exit. I consider this a bug, as once it is hooked up I was able to delete the subclass and return to stock NavigationController and it still worked.
Workaround for Segue Unwind in Swift not firing
Xcode 6 Beta 4 fixes the issue where unwind segues cannot find functions in Swift classes, so it isn't necessary to implement this workaround any longer.
Swift: performSegueWithIdentifier during unwind not working
In VC1 you need a function:
@IBAction func unwindToVC1(segue:UIStoryboardSegue) {
}
Then in your storyboard ctrl drag from the yellow view controller icon to the Exit icon and select unwindToVC1:
from the pop up
Give the unwind segue an identifier, say unwindToVC1
Now, in VC2, create your button touchUpInside
handler:
func buttonTapped(sender:UIButton) {
self.performSegueWithIdentifier("unwindToVC1")
}
when you set up your button programatically, add this method as the action handler:
button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)
xcode 7 unwind does not appear on exit
I fixed my issue by removing extension from the beginning of my code and implemented it in the view controller, after it Exit button start seeing my unwind function:
class ProductListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {
func updateSearchResultsForSearchController(searchController: UISearchController) {
filterContentForSearchText(searchController.searchBar.text!)
}
....
}
Related Topics
What Is Most Common and Correct Practice to Get a Cgfloat from an Nsnumber
Swift Override Function in Extension
Set Custom Images to the Uibarbuttonitem But It Doesn't Show Any Image
What Is Build Object File Extension in iOS
Why Is This Code Not Recognising the Nsstring as Being Equal
Datefromstring Returns Nil for Some Values
Custom Class Clusters in Swift
How to Determine the True Data Type of an Nsnumber
Eraser Not Working in iOS Drawing
Swiftui Landmarks App Tutorial Screen Navigates Back When Toggle Favorite
Application Not Automatically Launching in Device and Getting Error on Xcode
Add a Watermark on Video After Merging Video and Audio Asset into One in Swift3 iOS
iPhone Different Screen Sizes in Flash? (Getting Black Bars)
Presenting Uiviewcontroller from Skscene
This Class Is Not Key Value Coding-Compliant for the Key Xxxxxx