Unwind Segue Not Working in iOS 8

Unwind Segue not working in iOS 8

Apple has FIXED this bug in iOS 8.1

Temporary solutions for iOS 8.0

The unwind segue will not work only in next situation:


View structure: UITabBarController -> UINagivationController -> UIViewController1 -> UIViewController2


Normally (in iOS 7, 8.1), When unwind from UIViewController2 to UIViewController1, it will call viewControllerForUnwindSegueAction in UIViewController1.


However in iOS 8.0 and 8.0.x, it will call viewControllerForUnwindSegueAction in UITabBarController instead of UIViewController1, that is why unwind segue no longer working.


Solution: override viewControllerForUnwindSegueAction in UITabBarController by create a custom UITabBarController and use the custom one.

For Swift

CustomTabBarController.swift

import UIKit

class CustomTabBarController: UITabBarController {

override func viewControllerForUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject?) -> UIViewController? {
var resultVC = self.selectedViewController?.viewControllerForUnwindSegueAction(action, fromViewController: fromViewController, withSender: sender)
return resultVC
}

}

For old school Objective-C

CustomTabBarController.h

#import 

@interface CustomTabBarController : UITabBarController

@end

CustomTabBarController.m

#import "CustomTabBarController.h"

@interface CustomTabBarController ()

@end

@implementation CustomTabBarController

-(UIViewController *)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender
{
return [self.selectedViewController viewControllerForUnwindSegueAction:action fromViewController:fromViewController withSender:sender];
}

@end

==============================================================================

DO NOT USE ANY SOLUTIONS BELOW THIS POINT (they are out of date and just for reference)

Latest update on Sep 23

My new solution is pushing to a view that embedded in a navigation controller, and config that navigation controller to hide bottom bar on push(a tick box in IB). Then you will have a view looks like a modal view, the only different is the animate of pushing and popping. You can custom if you want

Updated: The solution below actually present the modal view under the tab bar, which will cause further view layout problems.

Change the segue type to Present As Popover will work only on iOS8 for iPhones, on iOS7 your app will crash.

Same here, to fix this, I set segue's presentation to current context(my app is for iphone only).

Default and full screen will not work.

Sample Image

xcode 8 swift: unwind segue transfer data is not working

You need to perform unwind and send data as following:

@IBAction func unwindToRaceViewController(sender: UIStoryboardSegue) 
{
if let sourceViewController = sender.sourceViewController
as? RaceViewController {
stat = sourceViewController.stat
}

You could refer to this article for unwind segues as alternative to delegate

You could also use delegates to pass data back to the previous controller.

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.)

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 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:

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

    @interface MyViewController (Workaround)
    - (IBAction)unwindToMyViewController: (UIStoryboardSegue *)segue;
    @end
  3. In 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

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 doesn't work

I created a dummy project with the same structure: Tab Bar Controller followed by Navigation Controller and it doesn't work so I suspect it has something to do with Tab Bar Controller and the structure of the Controllers.

End up using Present Modally segue and

dismissViewControllerAnimated(true, completion: nil)

Swift: unwind segue doesn't work

It looks like the view controller you're trying to unwind from is already the bottom of the UINavigationController's stack, so it's not going to do anything when the unwind is called.

If that UINavigationController is being called modally, call

self.navigationController?.dismiss(animated: true, completion: nil)

within the view controller where the button is being pressed.



Related Topics



Leave a reply



Submit