从UISplitViewControllers主视图到详细视图进行模态演示(make modally presentation from UISplitViewControllers primary

编程入门 行业动态 更新时间:2024-10-12 05:52:26
从UISplitViewControllers主视图到详细视图进行模态演示(make modally presentation from UISplitViewControllers primary view to detail view)

我在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!

更多推荐

本文发布于:2023-08-07 01:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主视图   视图   演示   模态   详细

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!