简体   繁体   English

在弹出窗口上显示模式视图时,不会在主视图中调用ViewDidAppear

[英]ViewDidAppear not called in main view when modal view is presented over a popover

I'm trying to use a popover as an intermediary menu between my main view and a modal view controller. 我正在尝试使用弹出框作为我的主视图和模式视图控制器之间的中间菜单。 I can successfully present the Modal view controller from the popover by using the following code: 我可以使用以下代码从弹出窗口成功展示Modal视图控制器:

UIStoryboard *storyboardiPad = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
cbwEditControlPanel *editCP = [storyboardiPad instantiateViewControllerWithIdentifier:@"EditCP"];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editCP];
[nav setToolbarHidden:NO];
[nav setModalPresentationStyle:UIModalPresentationFullScreen];
[nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:nav animated:YES completion:nil];
self.modalInPopover = NO;

The problem I'm running into is that when the EditCP modal view controller is dismissed, the main view controller never updates. 我遇到的问题是,当关闭EditCP模态视图控制器时,主视图控制器永远不会更新。 I have a pagecontroller on the main view that should be updated to reflect the number of pages as set in the EditCP modal view controller, but for some reason the modal view controller being called from the popover prevents the main view controller from updating the pagecontroller. 我在主视图上有一个pagecontroller,应该对其进行更新以反映EditCP模态视图控制器中设置的页面数,但是由于某些原因,从弹出窗口调用的模态视图控制器会阻止主视图控制器更新pagecontroller。 I've even tried calling the main view's "View Will Appear" method from the popover or modal view when they are dismissed, but even if the 'viewWillAppear' method is called the pageController will not update! 当关闭它们时,我什至尝试从弹出窗口或模式视图中调用主视图的“将出现视图”方法,但是即使调用了“ viewWillAppear”方法,pageController也不会更新!

Any ideas what is preventing the pageController from updating? 有什么想法阻止pageController更新吗? I even passed a reference to the pagecontroller to the modal view and tried to update it there, but it seems that from the time the popover is presented until it is dismissed, I cannot update the number of pages on the PageController. 我什至将对pagecontroller的引用传递给模式视图,并尝试在那里进行更新,但是似乎从显示弹出窗口到关闭弹出窗口之间,我无法更新PageController上的页面数。

Thank you! 谢谢!

So this is an old question but I also came across a similar problem recently when using a popover. 因此,这是一个古老的问题,但是最近在使用弹出窗口时,我也遇到了类似的问题。 My solution was to use an unwind segue to trigger my parent view to perform some action. 我的解决方案是使用放松搜索触发我的父视图执行某些操作。 In my case my parent view contains contact information and the popover contains a list of cites. 在我的情况下,我的父视图包含联系信息,而弹出窗口包含引用列表。 All I wanted to do was to have the parent view update with the new city once the user selected it from the popover. 我要做的就是一旦用户从弹出窗口中选择了新城市,就使父视图更新。 So in my parent view I create my unwind function as follows: 因此,在父视图中,我按如下方式创建展开函数:

In the .h: 在.h中:

- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue;

In the .m: 在他们中:

- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue
{
    [self updateTableForOffice];
}

In the above .m file is where you would have the logic to do whatever it is you want to in the parent view. 在上面的.m文件中,您可以执行父视图中想要执行的任何操作。 To connect this unwind segue go to the child view in the storyboard and control drag from the view icon to the exit icon. 要连接此解散链接,请转到情节提要中的子视图,然后控制从视图图标拖动到退出图标。 You should see a pop up with the name of your unwind segue. 您应该会看到一个弹出窗口,其中显示您正在放松的名字。

Finally, give that unwind segue a name and then in the child controller in the viewWillDisappear() function call the segue as follows: 最后,给该展开的名称指定一个名称,然后在子控制器中的viewWillDisappear()函数中按以下方式调用该名称:

- (void)viewWillDisappear:(BOOL)animated
{
    [self performSegueWithIdentifier:@"unwind-to-contact-tvc" sender:self];
}

I hope that helps. 希望对您有所帮助。 If someone has a better solution let me know. 如果有人有更好的解决方案,请告诉我。

Well, I half solved the problem. 好吧,我一半解决了这个问题。 The only way to get an update function when the popover disappeared was to stop using Storyboards and programmatically present the popover, using the main view as the delegate. 当弹出窗口消失时,获取更新功能的唯一方法是停止使用故事板,并以主视图作为委托以编程方式显示弹出窗口。 I then was able to update correctly inside the popoverControllerDidDismissPopover method. 然后,我能够在popoverControllerDidDismissPopover方法内正确更新。

However, I am still interested in finding a way to update the pageControl when the modal is dismissed, before the popover is dismissed. 但是,我仍然想找到一种方法,在消除模式时,消除弹出窗口之前更新pageControl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解除模态视图时未调用ViewDidAppear - ViewDidAppear not called when the modal view is dismissed TabBarController viewDidAppear 在呈现的视图控制器关闭时未调用 - TabBarController viewDidAppear not called when presented view controller dismissed 如何知道视图控制器是作为弹出窗口还是模态显示? - How to know if a view controller will be presented as a popover or modal? presentViewController不隐藏弹出框,弹出窗口出现在呈现的模态视图上 - presentViewController does not hide popover, popover appears on presented modal view 从viewDidAppear呈现时,模式弹出式控制器不会显示其内容 - Modal popover controller does not show its content when presented from viewDidAppear 从主视图控制器知道何时解散了所提供的模态视图控制器? - Knowing from the main view controller when the presented modal view controller is dismissed? viewDidAppear上的视图上是否已显示键盘? - Have keyboard already presented on view on viewDidAppear? 出现模态视图 controller 时暂停 animation - Pause animation when modal view controller is presented 在调用 viewDidAppear 之前未显示视图? 什么时候显示视图? - View is not shown before viewDidAppear called? When is the view shown? 我的viewDidAppear没有在视图控制器中调用 - My viewDidAppear not called in view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM