Unwind Segue无法在iOS 8中运行 [英] Unwind Segue not working in iOS 8

查看:80
本文介绍了Unwind Segue无法在iOS 8中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在iOS 7下工作正常,但是当为iOS 8构建时,展开的segues无效。

I have an app, that works fine under iOS 7, but when built for iOS 8 the unwind segues are not working.

我创建了一个新项目并添加了一个模态(带有tableviewcontroller的navigationcontroller)并尝试使用展开模式。不幸的是它也不起作用。正在展开的方法是在desination视图控制器中。展开segue是通过storyboard(tableviewcontroller中的Navigationbar按钮)创建的。当我点击按钮时,没有任何反应。没有日志输出,模态不会消失。它似乎也只影响模态segue。 push / popover正常解开。

I created a new project and added a modal (navigationcontroller with tableviewcontroller)and tried to use an unwind modal. Unfortunately it doesn't work either. The methods that are being unwind to, are in the desination view controller. The unwind segue is created through the storyboard (a Navigationbar button in the tableviewcontroller) When I tap the button, nothing happens. There is no log output and the modal does not disappear. It also only seems to affect modal segues. push/popover are unwound normally.

有没有人遇到过类似的问题而且有一个想法我怎么能解决它?

Has anyone had a similar problem and has an Idea how I could solve it?

推荐答案


Apple已在iOS 8.1中修复此错误

适用于iOS 8.0的临时解决方案


unwind segue仅在下一种情况下无效:

The unwind segue will not work only in next situation:


查看结构: UITabBarController - > UINagivationController - > UIViewController1 - > UIViewController2

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

通常(在iOS 7,8.1中),从 UIViewController2 展开到 UIViewController1 ,它将在 UIViewController1 中调用 viewControllerForUnwindSegueAction

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

但是在iOS 8.0和8.0.x中,它将会调用 viewControllerForUnwindSegue UITabBarController 中的操作,而不是 UIViewController1 ,这就是unwind segue不再有效的原因。

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.

解决方案:通过创建自定义 UITabBarController 覆盖 UITabBarController 中的 viewControllerForUnwindSegueAction 并使用自定义一个。

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


对于Swift

CustomTabBarController.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
    }

}

对于旧学校Objective-C

CustomTabBarController.h

CustomTabBarController.h

#import <UIKit/UIKit.h>

@interface CustomTabBarController : UITabBarController

@end

CustomTabBarController.m

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中的勾选框)。然后你会有一个看起来像模态视图的视图,唯一不同的是推动和弹出的动画。如果需要,您可以自定义

已更新:下面的解决方案实际上显示模态视图 标签栏,这将导致进一步的视图布局问题。

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

将segue类型更改为弹出窗口仅适用于 iOS8 iPhone >,在iOS7上你的应用程序将崩溃

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

同样,为了解决这个问题,我将segue的演示文稿设置为当前上下文(我的应用程序仅适用于iphone)。

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

默认和全屏无法使用。

这篇关于Unwind Segue无法在iOS 8中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆