我在UISplitViewController的主视图控制器中有一个加号按钮,我希望在我的详细视图中呈现一些模态,就像苹果在iPad中的地址簿中添加新联系人一样。 我尝试了一切,但没有尝试。 我设法做到了但是当我试图将我呈现的视图控制器嵌入到UINavigation控制器中时,我呈现的控制器覆盖了整个屏幕。 有什么建议么? 这是我的代码:
UINavigationController * navController = [self.splitViewController.viewControllers lastObject]; DetailTableViewController * controller =(DetailTableViewController *)navController.topViewController;
controller.definesPresentationContext = YES; controller.providesPresentationContextTransitionStyle = YES; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; EditTableViewController *etvc = (EditTableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"EditTableViewController"]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:etvc]; etvc.patient = patient; if (IDIOM == IPAD) { etvc.modalPresentationStyle = UIModalPresentationCurrentContext; [controller presentViewController:nav animated:YES completion:nil]; } else { [self presentViewController:nav animated:YES completion:nil]; }I have a plus button in my primary view controller of a UISplitViewController and i want to present something modally in my detail view, just like apple does when adding a new contact in address book in iPad. I have tried everything but nothing. I managed to do it but when i am trying to embed my presented view controller into a UINavigation controller then my presented controller covers the full screen. Any suggestions? Here is my code:
UINavigationController *navController = [self.splitViewController.viewControllers lastObject]; DetailTableViewController *controller = (DetailTableViewController *)navController.topViewController;
controller.definesPresentationContext = YES; controller.providesPresentationContextTransitionStyle = YES; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; EditTableViewController *etvc = (EditTableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"EditTableViewController"]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:etvc]; etvc.patient = patient; if (IDIOM == IPAD) { etvc.modalPresentationStyle = UIModalPresentationCurrentContext; [controller presentViewController:nav animated:YES completion:nil]; } else { [self presentViewController:nav animated:YES completion:nil]; }最满意答案
我刚刚通过创建自定义segue成功地解决了这个问题,其实现是:
- (void)perform { UIViewController *ctrl = self.sourceViewController; UIViewController *dest = self.destinationViewController; dest.modalPresentationStyle = UIModalPresentationCurrentContext; [ctrl presentViewController:dest animated:YES completion:nil]; }我正在通过我想要覆盖它的模态视图从我的详细视图控制器调用此segue来看到我想要的行为。
我想你的代码在哪里乱了,在这里:
etvc.modalPresentationStyle = UIModalPresentationCurrentContext;我认为它应该是:
nav.modalPresentationStyle = UIModalPresentationCurrentContext;虽然我还没有测试过。
请注意,Apple文档建议在iPhone(或“水平紧凑设备”)上忽略modalPresentationStyle,因此您的“IS_IPAD”检查可能是多余的。
希望这可以帮助!
I just successfully solved this problem by creating a custom segue whose implementation is:
- (void)perform { UIViewController *ctrl = self.sourceViewController; UIViewController *dest = self.destinationViewController; dest.modalPresentationStyle = UIModalPresentationCurrentContext; [ctrl presentViewController:dest animated:YES completion:nil]; }I'm seeing the behavior I want by invoking this segue from my detail view controller on the modal view I want to overlay it.
I think where your code is going haywire is here:
etvc.modalPresentationStyle = UIModalPresentationCurrentContext;I think it should be:
nav.modalPresentationStyle = UIModalPresentationCurrentContext;Though I haven't tested it.
Note that the Apple docs suggest that modalPresentationStyle is ignored on the iPhone (or on "horizontally compact devices"), so your "IS_IPAD" check may be redundant.
Hope this helps!
更多推荐
发布评论