Xcode 6 Storyboard Unwind Segue with fast non-output connection

When I try to connect a navigation bar button to an Exit ViewController element in Xcode 6 (I'm not quite sure that this is an Xcode 6 problem, but it is worth mentioning because it is in beta), it does not find the Swift function in the user class.

Button to Exit with whip

The function he should find:

@IBAction func unwindToList(segue: UIStoryboardSegue) { } 

I made another button on the screen to make sure that I can get an IBAction that works with Swift and that I am writing it correctly. This works great:

 @IBAction func test(sender: AnyObject) { NSLog("Test") } 

I saw this question that looks like the same problem, but according to the answers there it should work.

Xcode 6 is in beta, and of course Swift is very new, but he wanted to know if anyone had this before considering it as a potential bug.

+50
ios xcode swift
Jun 04 '14 at 5:19
source share
11 answers

This is a known issue with Xcode 6:

Undo segue actions declared in Swift classes not recognized by Interface Builder

To get around this you need to:

  • Change class MyViewController to @objc(MyViewController) class MyViewController
  • Create an Objective-C header file with a category for MyViewController that overrides the segue action.

     @interface MyViewController (Workaround) - (IBAction)unwindToMyViewController: (UIStoryboardSegue *)segue; @end 
  • In the storyboard, select an instance of MyViewController, clear its own class, then return it to MyViewController.

After these steps, you can reconnect the buttons to the output element.

Xcode 6 Release Notes , page 10

+55
Jun 04 '14 at 6:02
source share
β€” -

Instead of using the Objective-C workaround, Xcode 6 Beta 4, which can now be installed, supports the connection of expandable sections in Interface Builder. Now you can update it from the iOS Dev Center. Drag and drop the control from the user interface you want to call to go to the exit icon, and select the unwindToSegue function by placing the following code in the destination view controller.

 @IBAction func unwindToSegue (segue : UIStoryboardSegue) {} 
+50
Jul 22. '14 at 0:10
source share

I was finally able to make it work; xcode6 IB is really fragile right now (too many crashes). I had to restart the IDE before I could connect the navigation bar button element to the output element. I finished re-creating my test project and following the suggestion above (Xcode 6 Release Notes PDF, p. 10) to get it working. In addition, when adding the .h file, I tried to choose the project goal, which was removed by default. I also created my quick controller using the Cocoa Touch Class (vs empty swift file) template. I used modal segue in my navigation controller.

ListTableViewController.h

 #import <UIKit/UIKit.h> @interface ListTableViewController - (IBAction)unwindToList: (UIStoryboardSegue *)segue; @end 

ListTableViewController.swift

 import UIKit @objc(ListTableViewController) class ListTableViewController: UITableViewController { @IBAction func unwindToList(s:UIStoryboardSegue) { println("hello world"); } } 

hope that helps

+16
Jun 07 2018-11-14T00:
source share

Xcode 6 Beta 4, which is available for download, supports unwinding segues and an interface builder. I tested it myself in a small project.

+11
Jul 22 '14 at
source share

In Swift 2.3, I found that the external parameter name should be "withUnwindSegue":

 @IBAction func unwindToThisView(withUnwindSegue unwindSegue: UIStoryboardSegue) { ... } 
+5
Aug 14 '16 at 17:18
source share

Xcode 6.1 seems to have fixed this problem. Now you can configure unwinding in Swift with the following code:

 @IBAction func unwindToList(segue: UIStoryboardSegue) { // Nothing needed here, maybe a log statement // print("\(segue)") } 

This method, which may remain empty, must have a method signature of type UIStoryboardSegue, and not AnyObject or Interface Builder will not see it.

See TechNote 2298 for more information.

+2
Nov 19
source share

I had the same problem, also with Xcode Beta 4 at the beginning .. until I found out that I just forgot to add @IBOutlet for the Cancel and Save buttons in the corresponding controller. After that, I could connect the buttons using Exit-Icon :))

+1
Aug 01 '14 at 14:13
source share

If you always need the same view controller that you want to relax with, you can always just do:

 self.navigationController?.popViewControllerAnimated(true) 
+1
Apr 3 '15 at 16:59
source share

You might want to make sure that the original destination of the controller you are trying to restore is not embedded in the Container object. Xcode 6 does not have this.

+1
Jul 16 '15 at 2:31
source share

The answers above rely on ObjC to fix the problem, I found a clean Swift solution. When I added a segue handler to Swift, I managed to create a spinning segment in Interface Builder (Xcode 6.3), the handler was not called.

 @IBAction func unwindToParent(sender: UIStoryboardSegue) { dismissViewControllerAnimated(true, completion: nil) } 

So after digging canPerformUnwindSegueAction:fromViewController:withSender from the superclass returns false . So I redefined the implementation and it works:

 override func canPerformUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject) -> Bool { return action == Selector("unwindToParent:") } 

Update
Invalid code since I solved the problem without overriding canPerformUnwindSegueAction:fromViewController:withSender . The main mistake was to distinguish between the viewcontroller view and the presented view manager.

When an untied session is initiated, it must first find the nearest view controller in the navigation hierarchy that implements the unwind action specified when the unwind session was created. This view controller becomes the decoupling point. If no suitable view controller is found, the unwinding segment is interrupted.
source: Technical Note TN2298

So, define @IBAction in the viewcontroller, and not on the presented view controller. Thus, segue will have meaningful values ​​for the destinationViewController and sourceViewController , being respectively the representing and represented view manager.

0
Jun 18 '15 at 5:16
source share

Xcode --version 6.4 Swift 1.2

@IBAction func backButton (sender: AnyObject) {dodgingViewMessage (true, completion: zero)}

0
Aug 02 '15 at 16:36
source share



All Articles