在升级到 iOS 9/XCode 7 之前,我有一个运行良好的 unwind segue。
这是用于展开 segue 的 Storyboard 配置的屏幕截图:
在 UINavigationController 中按下“完成”按钮会触发展开序列。我通过覆盖 UINavigationController 中包含的 UITableViewController 中的 canPerformUnwindSegueAction 来拦截该操作。我这样做是为了验证数据。如果数据不完整,我返回 YES 以防止 segue 完全展开。
segue 实际上确实展开到正确的终止方法(在 NotificationsViewController 中);由于某种原因,canPerformUnwindSegueAction 永远不会被调用。
我试过了:
- 在情节提要中删除和添加展开转场。
- 用我自己的包含 canPerformUnwindSegueAction 的自定义 ViewController 覆盖 UITableViewController。(沿着这篇文章Unwind Segue not working in iOS 8)
- 与 #2 覆盖 allowedChildViewControllersForUnwindingFromSource 相同。(allowedChildViewControllersForUnwindingFromSource 也不会在原始 UITableViewController 上调用)
- 重新定位 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;
}
我难住了。任何关于我可以做些什么来进一步诊断或解决这个问题的想法将不胜感激!