模态 UINavigationController 隐藏,但不解除 [英] Modal UINavigationController hides although not dismisses

查看:22
本文介绍了模态 UINavigationController 隐藏,但不解除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在构建一个带有初始登录视图(名为 LoginVC 的视图控制器)的通用 iOS 应用程序,只是一个简单的 UIViewController.如果登录成功,应用程序将转到导航控制器 (MainNavigationVC).我通过 XCode 的 storyboard gui 创建了这个 segue,所以没有完成导航控制器的编程创建.导航控制器以全屏模式呈现,因此应用的其余部分在登录视图之上运行,此导航控制器是所有内容的核心.

Okay, so I'm building an universal iOS app with an initial login view (view controller named LoginVC), just a plain simple UIViewController. If the login is successful the app segues to an navigation controller (MainNavigationVC). I created this segue through the storyboard gui of XCode, so no programmatic creation of the nav controller is done. The nav controller is presented modally in fullscreen, so the rest of the app is run atop the login view, with this nav controller as the centerpiece of everything.

导航控制器包含一个视图(带有名为 UserStartPageVC 的视图控制器),并且在其导航栏中有一个注销按钮.此按钮向 UserStartPageVC 发送目标操作,目的是关闭导航控制器,从而将用户带回登录视图.

The navigation controller contains a view (with a view controller named UserStartPageVC), and in its navigation bar is a logout button. This button sends an target action to UserStartPageVC, with the goal of dismissing the nav controller thus bringing the user back to the login view.

到目前为止一切正常.我可以按预期登录并使用该应用程序.但!当我注销然后重新登录时,XCode 告诉我:

So far everything works fine. I can login and use the app as intended. But! When I log out and then re-login XCode tells me this:

警告!尝试呈现 <MainNavigationVC: 0x753110>在<登录VC:0x756fcf0>在演示过程中!

我想这意味着登录视图试图以模态方式显示 MainNavigationVC 导航控制器,但另一个已经显示,对吗?但是如何?可以在不显示的情况下呈现视图吗?

I suppose this means that the login view is trying to modally display a MainNavigationVC navigation controller, but another one is already displayed, right? But how? Can a view be presented without showing?

注销时如何摆脱旧的导航控制器?我尝试了几种关闭模态视图的方法,例如:

And how can I get rid of the old nav controller when logging out? I've tried several ways of dismissing the modal view, for instance:

  • 从 UserStartpageVC 运行中

  • from within UserStartpageVC running

[xdismissViewControllerAnimated:YES 完成:NULL]

[x dismissViewControllerAnimated:YES completion:NULL]

[xdismissModalViewControllerAnimated:YES]

[x dismissModalViewControllerAnimated:YES]

其中 x 是 self、self.parentViewController 或 self.presentingViewController.

where x is either self, self.parentViewController or self.presentingViewController.

  • 将 LoginVC 设置为 UserStartpageVC 中的一个属性并运行

  • setting the LoginVC as a property in UserStartpageVC and running

[self.loginVC deniedViewControllerAnimated:YES completion:NULL]

[self.loginVC dismissViewControllerAnimated:YES completion:NULL]

等等.

所有经过测试的调用实际上都让我回到了登录屏幕,所以它有点工作.

All of the tested calls actually brings me back to the login screen, so it's kind of working.

有什么想法吗?如果需要,可以提供相关的代码示例,我只是想不出哪些是感兴趣的.导航控制器的 seguing 没有代码(除了 performSegueWithIdentifier:sender:),而取消它的代码是我似乎无法理解的部分.

Any ideas? Relevant code samples can be provided if necessary, I just couldn't figure out which pieces that were of interest. The seguing to the navigation controller has no code (except for a performSegueWithIdentifier:sender:), and the code for dismissing it is the part I cannot seem to get straight.

作为旁注.到目前为止,这不是一个真正的问题.该应用程序运行,并且可以注销并重新登录,除了 XCode 中的错误消息外,没有任何其他副作用.但我想如果用户多次注销和登录,这将是内存泄漏,而且我不想被 Apple 不必要地拒绝.

As a sidenote. So far this isn't a REAL problem; the app runs, and it IS possible to logout and re-login without any other side-effects than an error message in XCode. But I suppose this will be a memory leak if users logout and login multiple times, and I'm not in the mood of an unnecessary rejection from Apple.

推荐答案

Hoopla!我的错.

Hoopla! My bad.

似乎我以一种愚蠢的方式从登录 API 调用中设置了通知观察.每次用户触发登录(或重新登录)时,它都会将自己添加为通知的观察者;结果是,每次登录完成时,它都会多执行一次 segue.

Seemed I had set up the notification observing from the login API call in a stupid way. For every time the user triggered a login (or re-login), it added itself as an observer for the notification; the result was that it performed one more segue for every time a login was done.

同时进行多个 segue 是......好吧,显然很糟糕.

And doing multiple segues at the same time, is... well, obviously bad.

这篇关于模态 UINavigationController 隐藏,但不解除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆