有效地在视图控制器之间切换

发布于 2024-12-27 16:06:10 字数 677 浏览 1 评论 0 原文

为了在我的 iOS 应用程序中的视图之间切换,我一直在使用模态视图控制器。它工作得很好,但是这是不好的编码习惯吗?它会对我的应用程序的内存使用产生不利影响吗?

为了回应要求更多信息的评论,我正在切换的视图是正常的信息视图。我使用三个视图来浏览我的应用程序:

  • 主视图:具有用于导航到特定信息视图的按钮
  • 信息视图:具有用于导航到特定网页以获取信息的按钮
  • Web 视图:通过 UIWebview 显示信息

我在以下位置有一个临时导航栏顶部用于导航“返回”和“主页”是主页。

总的来说,这是一个网络应用程序,其结构在其他视图中提供了菜单。我不想透露它具体做什么(这是我的想法),但这应该是足够的信息可以使用。

我目前正在这样的视图之间切换:

newViewController *newView = [[newViewController alloc] init];
[self presentModalViewController:newView animated:YES];

根据到目前为止的答案,模态视图旨在快速临时显示动画,但我正在寻找一种更永久的方法。

有更好的办法吗?请在您的回复中提供示例代码。谢谢你!

编辑:对于最初没有足够的信息,我深表歉意。我已经发布了更多信息。如果还需要什么,请评论。

In order to switch between views in my iOS app, I have been using Modal View Controllers. It works fine, but is this bad coding practice? Will it be detrimental to the memory usage of my app?

In response to comments asking for more information, the views I am switching between are normal informational views. I am using three views to navigate through my app:

  • Main View: Has buttons to navigate to specific informational views
  • Info View: Has buttons to navigate to specific web pages for information
  • Web View: Displays information through a UIWebview

I have an improvised navigation bar at the top for navigating "back" and "home" do the main page.

Overall, this is a web app with structure provided with menus in other views. I don't want to reveal what it does specifically (it's my idea), however this should be enough information to work with.

I am currently switching between views like this:

newViewController *newView = [[newViewController alloc] init];
[self presentModalViewController:newView animated:YES];

Based on the answers so far, Modal Views are meant to quickly and temporarily display animations, but I am looking for a more permanent approach.

Is there a better way? Please provide example code with your response. Thank you!

EDIT: I apologize for originally not having enough information. I have posted a lot more information. If you need anything else, please comment.

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

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

发布评论

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

评论(2

幸福%小乖 2025-01-03 16:06:10

使用模态视图控制器通常是在您需要临时显示视图时使用,例如当 Apple 的消息应用程序呈现“新消息”控制器时。做你想做的事情的另一种方法,需要更多的设置,是:

[self.navigationController pushViewController:newView animated:YES];

可以找到概述两者之间差异的很好的解释 此处 以及 Stack 上的问题溢出此处此处。关于如何设置 UINavigationController 的一个不错的小教程可以在 此处涵盖了自定义动画的主题,同时提供了一些源代码此处也可能对您有所帮助。唷。这是很多链接。

Using modal view controllers is usually reserved for times when you need to display a view temporarily, as when the 'new message' controller is presented by Apple's Messages app. Another way to do what you want, which requires a little more setup, is:

[self.navigationController pushViewController:newView animated:YES];

A nice explanation outlining the difference between the two can be found here as well as questions on Stack Overflow here and here. A nice little tutorial on how to set up a UINavigationController can be found here, and a previous SO question here covers the topic of custom animations, while some source code provided here might also help you out. Phew. That's a lot of links.

瀞厅☆埖开 2025-01-03 16:06:10

模态视图控制器有一个明确的目的,即获取程序流中的“额外信息”。它们的设计目的不是消耗更多/更少的内存。事实上,没有任何特定样式的视图控制器在设计时考虑了内存消耗。如果您正在收集分层信息,UINavigationControllerUITableViewController 结合可能是最佳选择。同样,如果您需要一条信息(并且,比如说,如果没有获取此信息,您就无法继续操作),您会呈现一个模式视图控制器(某种意义上)来提醒用户。

Modal view controllers have a definite purpose of acquiring 'extra information' in a program flow. They are not designed to consume more/less memory. In fact no particular style of view controller is designed with memory consumption in mind. If you are gathering hierarchical bits of information, UINavigationController coupled with UITableViewController might be the way to go. Likewise, if you need a piece of information (and, say, you can't proceed without getting this information) you present a modal view controller (sort of) alerting the user.

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