在没有导航控制器的情况下关闭多个模态视图

发布于 2024-11-06 14:28:33 字数 394 浏览 3 评论 0原文

我没有在我的应用程序中正确计划视图导航,因此用户可能会经历一个将模态视图堆叠在一起的循环,并且从那里只能通过时间访问根视图控制器 -手动消除每个重复视图的消耗过程。

我不能直接使用 popToRootViewControllerAnimated: 而不使用导航控制器(当时反复调用 presetModalViewController:animated: 似乎是个好主意) ,所以除非谷歌有什么事情瞒着我,否则我就完全迷失了。

重写一半的导航代码并不理想,但如果这确实是唯一的选择,我会尝试一下。
避免这种情况肯定会更好。

不知道什么代码会有帮助(如果有的话)。它只是用 UIViewController 的几个子类来呈现/解除模态视图控制器

I didn't plan ahead properly for view navigation in my app, so it's possible for the user to go through a loop that just stacks modal views on top of each other, and from there the root view controller is only accessible through the time-consuming process of manually dismissing each and every repeated view.

I can't just go ahead and use popToRootViewControllerAnimated: without a navigation controller on top of it all (calling presetModalViewController:animated: repeatedly seemed like a good idea at the time), so unless there's something Google is hiding from me, I'm completely lost.

Rewriting half the navigation code is not ideal, but if that really is the only option, I'll give it a shot.
Avoiding that would certainly be preferable.

No idea what code would be helpful, if any. It's just presenting/dismissing modal view controllers with a few subclasses of UIViewController

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

舟遥客 2024-11-13 14:28:33

答案A:简单答案;

只需在您想要查看的视图上调用 dismissModalViewController:animated: 即可。

答案B:真实答案;

对您来说,将其重构为导航控制器应用程序并不困难,我将启动一个导航应用程序的新项目,并查看应用程序委托中的方法,并模拟该行为。

然后,当您正常呈现时,只需推送([self.navigationController PushViewController:控制器动画:YES]),您的解雇将变成弹出([self.navigationController popViewControllerAnimated:YES])

希望有帮助

answer A: easy answer;

just call dismissModalViewController:animated: on the view that you want to see.

answer B: real answer;

It will not be hard for you to re-factor as a Navigation Controller app, I would start a new project that is a Navigation app, and look at the methods in the application delegate, and emulate that behavior.

then when you would normally present, just push ([self.navigationController pushViewController: controller animated: YES]) and your dismiss will become a pop ([self.navigationController popViewControllerAnimated: YES])

Hope that helps

怂人 2024-11-13 14:28:33

@Grady 的两个答案都是正确的。查看 -dismissModalViewController:animated: 告诉您:

如果你呈现几个模态视图
连续控制器,因此
构建模态视图堆栈
控制器,在
查看堆栈中较低的控制器
忽略其直接子视图
控制器和所有视图控制器
在堆栈上那个孩子的上方。什么时候
发生这种情况,只有最顶层的视图
以动画方式被解雇;
任何中间视图控制器都是
只需从堆栈中删除即可。

您应该使用 -dismiss... 而不是从导航堆栈中弹出控制器,因为模式控制器甚至可能不是导航堆栈的一部分。不过,如果您发现您的应用程序应该是基于导航的应用程序,那么请花点时间实现它。如果这是一个大量的工作,那么它可能是无论如何都需要完成的工作。

Both @Grady's answers are the right ones. A look at the documentation for -dismissModalViewController:animated: tells you:

If you present several modal view
controllers in succession, and thus
build a stack of modal view
controllers, calling this method on a
view controller lower in the stack
dismisses its immediate child view
controller and all view controllers
above that child on the stack. When
this happens, only the top-most view
is dismissed in an animated fashion;
any intermediate view controllers are
simply removed from the stack.

You should use -dismiss... rather than popping the controller from the nav stack, since modal controllers may not even be part of the navigation stack. Nevertheless, if you find that your app should have been a navigation-based app, then just take the time to make it so. If that's a lot of work, it's probably work that needs to be done anyway.

想你只要分分秒秒 2024-11-13 14:28:33

更改 UIViewController 中的视图属性不起作用?

Change the view property in your UIViewController doesn't work?

っ〆星空下的拥抱 2024-11-13 14:28:33

好吧,现在我明白了。底线以下是我不应该做的事情。我不应该尝试包含循环增长的堆栈,而应该一开始就阻止它。

也就是说,“加载”按钮不再生成另一个视图。相反,它会忽略当前视图,该视图只能是加载视图的子视图,从而给出新视图的错觉,并完全消除堆栈不受控制增长的问题。


同样,这是错误的选项:

全局、一些#define 的字符串和一些 if/else 堆栈,并且缺少导航控制器不是问题。

如果有人对我为实现这一目标所做的事情(和/或稍后修改会有多少乐趣)感兴趣,我会将其中的一些内容放入这个答案中。它并不漂亮,而且写起来很痛苦(主要是因为新代码跨越四个文件并悄然中断),但它正是我想要的。

Okay, now I got it. Below the line is what I should never have done. Rather than trying to contain a loop-grown stack, I should have just blocked it to begin with.

That is, the "Load" button no longer spawns another view. Instead, it dismisses the current view, which can only ever be a child of the Load view, giving the illusion of a new view and completely removing the problem of an uncontrollably growing stack.


Again, this is the wrong option:

A global, a few #define'd strings, and some if/else stacks, and the lack of a navigation controller is not a problem.

If anyone is interested in what I've done to achieve this (and/or how much fun it'll be to modify later), I'll drop some of the it into this answer. It's not pretty and it was a pain to write (mostly because the new code spans four files and breaks quietly), but it does exactly what I want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文