NZK*_*Koz 12 cocoa-touch uistoryboard uistoryboardsegue
我正在尝试将我们的应用程序转换为故事板,并且在处理自定义容器控制器时遇到了我认为处理展开segue的错误.我们有一个视图控制器,它显示另一个并使用视图控制器包含api来执行此操作,我在IB中连接segue然后为实现选择一个自定义类.perform方法看起来像这样:
-(void) perform {
UIViewController *container = [self sourceViewController];
UIViewController *child = [self destinationViewController];
[container addChildViewController:child];
[container.view addSubview:child.view];
child.view.center = container.view.center;
[UIView transitionWithView:container.view
duration:0.35
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
child.view.alpha = 1;
} completion:^(BOOL finished) {
[child didMoveToParentViewController:container];
}];
}
Run Code Online (Sandbox Code Playgroud)
这完全有效,但是我不能让它执行解开segue回到容器控制器.我重写viewControllerForUnwindSegueAction:fromViewController:withSender:并确保它返回正确的值:
-(UIViewController *) viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
id default = [super viewControllerForUnwindSegueAction:action fromViewController:fromViewController withSender:sender];
NSAssert1(default == self, @"Expected the default view controller to be self but was %@", default);
return default;
}
Run Code Online (Sandbox Code Playgroud)
我还可以确认canPerformUnwindSegueAction:fromViewController:正在调用withSender并做正确的事情,但要确保我重写它以返回YES
-(BOOL) canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我期望发生的下一步是segueForUnwindingToViewController:fromViewController:identifier:要调用,但它永远不会.而是应用程序崩溃与NSInternalInconsistencyException.
2012-10-01 10:56:33.627 UnwindSegues[12770:c07] *** Assertion failure in -[UIStoryboardUnwindSegueTemplate _perform:], /SourceCache/UIKit_Sim/UIKit-2372/UIStoryboardUnwindSegueTemplate.m:78
2012-10-01 10:56:33.628 UnwindSegues[12770:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not find a view controller to execute unwinding for <USCustomContainerViewController: 0x75949a0>'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1c8de78 0xb61f35 0x581711 0x45ab54 0x10df705 0x16920 0x168b8 0xd7671 0xd7bcf 0xd6d38 0x4633f 0x46552 0x243aa 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x1be87e3 0x1be8668 0x1365c 0x1e7d 0x1da5)
libc++abi.dylib: terminate called throwing an exception
Run Code Online (Sandbox Code Playgroud)
有没有人成功使用unwind segue和视图控制器包含API?知道我错过了哪一步?我已经向github上传了一个演示项目,它展示了我能想到的最简单的演示项目中的问题.
你的例子中的问题是那里没有.这太简单了.首先,您以一种相当奇怪的方式创建容器视图控制器(您不使用新的IB"容器视图"来帮助您执行此操作).其次,你没有什么可以解除的:没有任何东西被推送或呈现在任何东西之上.
我有显示出工作的例子canPerformUnwindSegueAction还真是咨询父级链,以及viewControllerForUnwindSegueAction与segueForUnwindingToViewController被称为有效的,如果出现在正确的地方.看到:
我现在还在github上创建了一个原始示例的分支,对其进行了更正,以便说明这些功能:
https://github.com/mattneub/UnwindSegues
实际上并不需要 "展开" ,但它确实显示了在涉及自定义容器视图控制器时如何使用"展开".
这似乎是一个错误 \xe2\x80\x93 我也希望展开转场能够像您实现的那样工作。
\n\n我使用的解决方法是显式关闭 IBAction 方法中呈现的视图控制器:
\n\n- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController\n fromViewController:(UIViewController *)fromViewController\n identifier:(NSString *)identifier\n{\n return [[UIStoryboardSegue alloc] initWithIdentifier:identifier\n source:fromViewController\n destination:toViewController];\n}\n\n- (IBAction)unwind:(UIStoryboardSegue*)segue\n{\n UIViewController *vc = segue.sourceViewController;\n [vc willMoveToParentViewController:nil];\n if ([vc respondsToSelector:@selector(beginAppearanceTransition:animated:)]) {\n [vc beginAppearanceTransition:NO animated:YES]; // iOS 6\n }\n UIView *modal = vc.view;\n UIView *target = [[segue destinationViewController] view];\n [UIView animateWithDuration:duration animations:^{\n modal.frame = CGRectMake(0, target.bounds.size.height, modal.frame.size.width, modal.frame.size.height);\n } completion:^(BOOL finished) {\n [modal removeFromSuperview];\n [vc removeFromParentViewController];\n if ([vc respondsToSelector:@selector(endAppearanceTransition)]) {\n [vc endAppearanceTransition];\n }\n }];\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
7446 次 |
| 最近记录: |