Unwind segue not working
If you read the tutorial carefully you will see that the unwind method needs to be in the UIViewController
that you are unwinding to - from the tutorial -
An unwind segue is created by adding an action method to the
destination view controller (the view controller you want to unwind
to)....
Because you want to unwind back to XYZToDoListTableViewController, you need to add an action method with this format to the XYZToDoListTableViewController interface and implementation.
So, you should create your unwindToList
method in the table view controller, not in the add view controller.
unwind segue Xcode 10 swift with navigation controller not working
From your comments, I'm guessing that the problem is that there is no FavouritesTableViewController in the view controller hierarchy at the time that the Save button is pressed. You cannot unwind to something that isn't already present: "unwind" means go back to something that was instantiated earlier and remains present, above the current view controller in the view controller hierarchy.
For example, let's say we have
UINavigationController -> (root view controller) -> FavouritesTableViewController
-> (push) ExplorationResultViewController
Now we can unwind from the Exploration controller to the Favourites controller, because the Favorites controller is already in the hierarchy before the Exploration controller. It sounds like maybe you are not appreciating that fact.
Unwind of custom segue not triggered
I got your example to work like this. ViewController is the first view controller; ViewController2 is the second view controller:
class ViewController: UIViewController {
@IBAction func unwindToFeed(_ segue: UIStoryboardSegue) {
let child = self.childViewControllers[0]
child.willMove(toParentViewController: nil)
child.view.removeFromSuperview()
child.removeFromParentViewController()
}
}
class MySegue: UIStoryboardSegue {
override func perform() {
let sourceVC = self.source as! ViewController
let destinationVC = self.destination as! ViewController2
sourceVC.addChildViewController(destinationVC)
sourceVC.view.addSubview(destinationVC.view)
destinationVC.view.frame = sourceVC.view.bounds
destinationVC.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
destinationVC.didMove(toParentViewController: sourceVC)
}
}
class ViewController2 : UIViewController {
}
Note that unwindToFeed
is (and must be) in the first view controller. It is meaningless to put it in the second view controller, as the second view controller is the source, not the destination, of the unwind.
Now I'd like to make some comments about the problem and my answer:
This is an iOS 10 example.
segueForUnwinding
will never be called in iOS 10; it was abandoned after iOS 8 and was subsequently deprecated.The iOS 9/10 equivalent of
segueForUnwinding
isunwind(for:towardsViewController:)
. I did try implementing it, but I found that it was called in ViewController2, not in ViewController. I regard that as a bug in iOS 10, and am reporting it to Apple.
Swift 4 Unwind segue not working on navigation controller
Add this unwind to your RSVP controller:
@IBAction func unwindToThisViewController(segue: UIStoryboardSegue) {
print("IM BACK")
}
Then control + drag the button in your detail controller up to the exit and select the method: unwindToThisViewController
Just tested this on xcode swift 4 and it should work
I'm not sure why, but when I "overrode" unwind, it didn't work for me either, so I set up my own ibaction
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.)
Related Topics
Response Struct Does Not Like Codingkeys
Comparing Two Enum Variables Regardless of Their Associated Values
Making Button Span Across VStack
Set Insets to the Collectionview Programmatically in Swift
Type of Optionals Cannot Be Inferred Correctly in Swift 2.2
Enum's Rawvalue Property Not Recognized
Why Does Somestruct() Is Anyobject Return True
Using "Codable" to Set Property Values Doesn't Work Through Inheritance
With Swiftui, How to Constrain a View's Size to Another Non-Sibling View
How to Get Rid of Array Brackets While Printing
Swift iOS 9: Section Header Change Position After Reload Data
How to Set a Function as Function Argument in Swift 3
How to Compare Result to .Succeed in Swift
Filteredarrayusingpredicate Does Not Exist in Swift Array
How to Create a Directory in Downloads Folder with Swift on MACos? Permission Exception