8

我正在使用 Xcode 4.5 和 iOS 6。

我正在构建一个使用故事板的通用应用程序。我有一个视图控制器,在导航栏中有一个按钮。当点击按钮时,我使用 segue 将另一个视图控制器呈现为模态。模态视图控制器在其导航栏中有一个取消和一个保存按钮。在故事板中,模态按钮项链接到新的Exit动作上的动作,该动作应该展开到父视图控制器,关闭模态,并调用动作处理程序。

这在 iPhone 上运行良好,但我在 iPad 上看到了问题。在 iPad 上,当模式全屏显示时,一切正常。当我将模式更改为 Page Sheet 或 Form Sheet(在我的情况下这是所需的行为)时,会调用动作处理程序,但不会自动关闭模态视图控制器。

有没有其他人看到过这种行为?你有没有做些什么来修复它?

谢谢你。

4

4 回答 4

6

Thanks for asking about this, since I've just encountered the same issue. I assume that it's a bug, but I have not yet filed it with Apple. In the meantime, the easy workaround is to call dismissViewController:animated: in your unwind: implementation (that is, in the action method connected to the unwind segue through the Exit icon), thus dimissing the modal view yourself.

My only worry about this solution is that if this is a bug and Apple eventually fixes it, will their fix break any code using this workaround? Only time will tell...

Later Edit: I have discovered a much nicer workaround. Subclass the parent (container) class of the class you want to unwind to, and implement unwind there instead. For example, in my app, the situation looks like this:

UISplitViewController
    UINavigationController
        MasterViewController
    UINavigationController
        DetailViewController ----> modal segue ----> ThirdViewController

The exit / unwind segue from ThirdViewController back to DetailViewController demonstrates the bug - the unwind: implementation is called, but the form view is not dismissed. But if I subclass UISplitViewController and implement unwind: there, it works fine. (The unwind: implementation can be empty; the point is that the form view is dismissed automatically.) So evidently this is an issue having to do with container view controllers, and you can solve it by letting the container handle it.

See my example project, uploaded to https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch19p561containerViewControllerStoryboard3Bug

于 2012-11-11T20:05:52.783 回答
4

如果模态视图控制器自动关闭,这很酷,但在 Apple 的示例中他们使用模态转换进行 segue,然后在展开(退出)操作中显式调用 dismissViewControllerAnimated:completion: 以关闭它。

于 2013-01-18T16:51:12.997 回答
2

我有同样的问题,所以我所做的是:

- (IBAction)closeSalesJournal:(UIStoryboardSegue *)segue
{
    // Unwind Segue
    NSLog(@"Closed Sales journal VC");

    // For iPad, need to dismiss the view controller manually
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

那样的话,我肯定会离开 iPhone 的标准方式并用 iPad 强制解雇。

于 2013-08-11T12:47:32.717 回答
0

我有一个类似的问题。我的模态转场不会放松。在浪费了太多时间之后,我发现了问题所在。是我的错。

- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender我在目标控制器中写得不好。没想到我刚刚写了新的 segue,所以它又回来了NO。从本质上讲,我的新 segue 被告知不要被其他代码放松。

于 2014-01-11T00:10:02.913 回答