gpt4 book ai didi

ios - Unwind Segue 在 iOS 8 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 04:57:37 24 4
gpt4 key购买 nike

我有一个应用程序,它在 iOS 7 下运行良好,但是当为 iOS 8 构建时,unwind segues 不工作。

我创建了一个新项目并添加了一个模态(带有 tableviewcontroller 的导航 Controller )并尝试使用展开模态。不幸的是它也不起作用。正在展开的方法位于目标 View Controller 中。 unwind segue 是通过 Storyboard创建的(tableviewcontroller 中的导航栏按钮)当我点击按钮时,没有任何反应。没有日志输出,模态也没有消失。它似乎也只影响模态转场。 push/popover 正常展开。

有没有人遇到过类似的问题并且知道我该如何解决它?

最佳答案

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.

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

对于 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

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

9 月 23 日的最新更新

我的新解决方案是推送到嵌入在导航 Controller 中的 View ,并将该导航 Controller 配置为在推送时隐藏底部栏(IB 中的勾选框)。然后你会看到一个看起来像模态视图的 View ,唯一不同的是推送和弹出的动画。您可以根据需要自定义

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

将 segue 类型更改为 Present As Popover 仅适用于 iOS8 for iPhone在 iOS7 上你的应用程序会崩溃

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

默认和全屏将不起作用。

enter image description here

关于ios - Unwind Segue 在 iOS 8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25845098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com