Apple has FIXED this bug in iOS 8.1
Temporary solutions for iOS 8.0
只有在下一种情况下,放松阶段才会起作用:
View structure: UITabBarController -> UINagivationController -> UIViewController1 -> UIViewController2
通常(在iOS 7、8.1中),当从UIViewController2放松到UIViewController1时,它会在UIViewController1中呼叫viewControllerForUnwindSegueAction.
但是在iOS 8.0和8.0中.x、 它将在UITabBarController中调用viewControllerForUnwindSegueAction而不是UIViewController1,这就是为什么unwind segue不再工作的原因.
Solution:通过创建自定义UITabBarController并使用自定义UITabBarController来覆盖UITabBarController中的viewControllerForUnwindSegueAction.
For Swift
CustomTabBarController.敏捷的
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 <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
==============================================================================
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:下面的解决方案实际上是tab bar下的modal view,这将导致进一步的视图布局问题.
将segue类型更改为Present As Popover将仅适用于iPhones和on iOS7 your app will crash的iOS8.
同样,为了解决这个问题,我将segue的演示设置为当前上下文(我的应用程序仅适用于iphone).
默认和全屏将不起作用.