Apple 已在 iOS 8.1 中修复了此错误
iOS 8.0 的临时解决方案
unwind segue 仅在下一种情况下不起作用:
视图结构:UITabBarController -> UINagivationController -> UIViewController1 -> UIViewController2
一般情况下(iOS 7、8.1),当从UIViewController2展开到UIViewController1时,会在UIViewController1中调用viewControllerForUnwindSegueAction /strong>。
然而在 iOS 8.0 和 8.0.x 中,它会在 UITabBarController 中调用 viewControllerForUnwindSegueAction 而不是 UIViewController1,这就是为什么 unwind segue 不再工作。
解决方案:通过创建自定义 UITabBarController 覆盖 UITabBarController 中的 viewControllerForUnwindSegueAction 并使用自定义的。 p>
对于斯威夫特
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
}
}
对于老式的 Objective-C
CustomTabBarController.h
#import <UIKit/UIKit.h>
@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
================================================ ================================
不要使用低于此点的任何解决方案(它们已过时,仅供参考)
9 月 23 日最新更新
我的新解决方案是推送到嵌入在导航控制器中的视图,并将导航控制器配置为在推送时隐藏底部栏(IB 中的复选框)。然后你会看到一个看起来像模态视图的视图,唯一不同的是推送和弹出的动画。您可以根据需要自定义
更新:下面的解决方案实际上是在标签栏下呈现了模态视图,这会导致进一步的视图布局问题。
将 segue 类型更改为 Present As Popover 仅适用于 iPhones 的 iOS8,在 iOS7 上您的应用会崩溃。
同样,为了解决这个问题,我将 segue 的演示文稿设置为当前上下文(我的应用仅适用于 iphone)。
默认和全屏都不起作用。