我使用以下命令创建了一个自定义容器视图控制器新的 UIViewController 容器视图控制器方法 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW81在 iOS 5 中。
问题是,即使我的容器控制器的子 UIViewController 有definesPresentationContext = YES http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/definesPresentationContext,当它创建并呈现另一个模态视图控制器 http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html,UIKit 将容器(而不是子容器)设置为呈现控制器。
例如,在 MyChildViewController.m 中:
- (void)showMailComposeView:(id)sender {
__block MFMailComposeViewController *vc =
[[MFMailComposeViewController alloc] init];
vc.mailComposeDelegate = self;
vc.subject = @"Subject";
self.definesPresentationContext = YES;
[self presentViewController:vc animated:YES completion:^{
if ([self.modalViewController isEqual:vc])
NSLog(@"This should print...");
if ([vc.presentingViewController isEqual:self.parentViewController])
NSLog(@"... but this shouldn't");
// NOTE: Both log statements printed
}];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
[self dismissViewControllerAnimated:YES completion:^{}];
// NOTE: self.parentViewController.view now displays instead of self.view
}
我哪里错了?
我如何确保它是child当模态视图(而不是容器视图)被关闭时,哪个视图会被显示?
在呈现视图控制器之前添加此行:
vc.modalPresentationStyle = UIModalPresentationCurrentContext
如果您已经在视图控制器链上完成了所有正确的父子操作,这将导致呈现的视图替换 MyChildViewController 的视图,然后当呈现的视图被关闭时,MyChildViewController 的视图将返回。
哦,我忘了提一下,即便如此,这也只能在 iPad 上运行。呈现的视图控制器的视图始终占据 iPhone 上的整个屏幕 - 它始终从根视图呈现。
EDIT:从 iOS 8 开始,此功能在 iPhone 上也可用。 (弹出窗口和分割视图也是如此 - 基本上,大多数“仅在 iPad 上”形式的声明在 iOS 8 中都变成了错误,在我看来,这是一个很棒的消息。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)