1

在升级到 iOS 9/XCode 7 之前,我有一个运行良好的 unwind segue。

这是用于展开 segue 的 Storyboard 配置的屏幕截图: 在此处输入图像描述

在 UINavigationController 中按下“完成”按钮会触发展开序列。我通过覆盖 UINavigationController 中包含的 UITableViewController 中的 canPerformUnwindSegueAction 来拦截该操作。我这样做是为了验证数据。如果数据不完整,我返回 YES 以防止 segue 完全展开。

segue 实际上确实展开到正确的终止方法(在 NotificationsViewController 中);由于某种原因,canPerformUnwindSegueAction 永远不会被调用。

我试过了:

  1. 在情节提要中删除和添加展开转场。
  2. 用我自己的包含 canPerformUnwindSegueAction 的自定义 ViewController 覆盖 UITableViewController。(沿着这篇文章Unwind Segue not working in iOS 8
  3. 与 #2 覆盖 allowedChildViewControllersForUnwindingFromSource 相同。(allowedChildViewControllersForUnwindingFromSource 也不会在原始 UITableViewController 上调用)
  4. 重新定位 iOS 8.2(最后一个工作版本),但这也不起作用。升级到 iOS 9 时,我注意到 Xcode 对 .storyboard 文件进行了 80 多次更改……也许那里出了点问题?

这是一个回溯,显示了按下“完成”按钮时会发生什么:

*** First throw call stack:
(
    0   CoreFoundation                      __exceptionPreprocess + 165
    1   libobjc.A.dylib                     objc_exception_throw + 48
    2   CoreFoundation                      -[__NSDictionaryM setObject:forKey:] + 1042
    3   Autodar                             -[Notification JSONDictionary] + 608
    4   Autodar                             -[RESTClient createNotification:withCompletionBlock:] + 290
    5   Autodar                             -[NotificationsViewController createBackendNotification:atIndex:] + 247
    6   Autodar                             -[NotificationsViewController unwindFromDone:] + 705
    7   UIKit                               -[UIStoryboardUnwindSegueTemplate _performWithDestinationViewController:sender:] + 214
    8   UIKit                               -[UIStoryboardUnwindSegueTemplate _perform:] + 86
    9   UIKit                               -[UIStoryboardSegueTemplate perform:] + 156
    10  UIKit                               -[UIApplication sendAction:to:from:forEvent:] + 92
    11  UIKit                               -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 152
    12  UIKit                               -[UIApplication sendAction:to:from:forEvent:] + 92
    13  UIKit                               -[UIControl sendAction:to:forEvent:] + 67
    14  UIKit                               -[UIControl _sendActionsForEvents:withEvent:] + 327
    15  UIKit                               -[UIControl _sendActionsForEvents:withEvent:] + 706
    16  UIKit                               -[UIControl touchesEnded:withEvent:] + 601
    17  UIKit                               -[UIWindow _sendTouchesForEvent:] + 835

这是我在 UITableViewController 中覆盖 canPeformUnwindSegueAction 的地方:

// Respond to "Done" button being pushed
// Return:
//   YES: to stop unwind and display popover for validation message
//   NO:  to unwind back to NotificationsViewController
- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
  // return YES if data is incorrect
  return NO;
}

我难住了。任何关于我可以做些什么来进一步诊断或解决这个问题的想法将不胜感激!

4

3 回答 3

0

看起来你想要倒带的东西是从导航控制器的顶部呈现的,对吧?这会将导航控制器从响应者链中取出,因此 segue 回调永远不会到达堆栈中的控制器。至少,前段时间我在尝试从下堆栈提供自定义 segue 时遇到了类似的问题,这就是我找到的解释。

我的情况的解决方案是将呈现的工作表推入导航控制器而不是呈现它。然后一切都按预期进行。因此,如果这确实是一张展示的表格,请尝试推送而不是展示,看看是否对您有所帮助。

于 2016-06-17T22:16:06.617 回答
0

我能够通过使用 shouldPerformSegueWithIdentifier 回调而不是 canPerformUnwindSegueAction 来解决这个问题。

这篇文章如何在展开 segue 动作之前做一些事情?暗示使用这种方法。

从情节提要的角度来看,除了向展开转场添加标识符之外,我不需要做任何不同的事情。

我不知道为什么 canPerformUnwindSegueAction 之前在 iOS8.x 中被调用并在 iOS9.x 中停止,但希望这也可以帮助其他人。

于 2016-06-21T00:27:25.130 回答
0

当当前视图控制器实现 action 方法并且与 fromViewController 参数中的视图控制器不同时,此方法的默认实现返回 YES。

所以看起来你在同一个 ViewController 中实现了这个方法fromViewController

于 2016-06-18T17:40:13.667 回答