如何最好地将使用一个 UIViewController 将所有页面作为 UIView 处理的图书应用程序转换为 StoryBoarding 和 UIPageView?

发布于 2025-01-07 08:14:44 字数 218 浏览 5 评论 0原文

我有一个图书应用程序,大约有 30 页,每个页面都是一个 UIViewController 中的 UIView。我想将其转换为使用 StoryBoarding 和 UIPageViews 的应用程序。看起来 UIPageView 中的每个“页面”都必须是 UIViewController,而不是 UIView。解决这个问题的最佳方法是什么?我需要为每个 UIView 页面制作一个 UIViewController 吗?

I have a book app that has about 30 pages that are each a UIView in a single UIViewController. I want to transition this to an app that uses StoryBoarding and UIPageViews. It looks like each of the "pages" in UIPageView must be a UIViewController, not a UIView. What would be the best way of going about this? Do I need to make a UIViewController out of each UIView page?

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

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

发布评论

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

评论(2

谜泪 2025-01-14 08:14:45

是的。将所有 UIView 子类重写为 UIViewController 子类。我已经在我的几个项目中做到了这一点,结果发现这有点乏味。对于我的项目,我发现最简单的方法是创建一个新的 Xcode 项目并构建新的基础设施。然后为每个旧的 UIView 类创建新的 UIViewController 类。然后,我将旧 UIView 类中的大部分代码复制并粘贴到新的 UIViewController 类中。我将很多 self 更改为 self.viewUIViewController 的生命周期比 UIView 稍微复杂一些,因此我最终将一些初始化代码从指定的初始化器移至 viewDidLoadviewWillAppear<我的 UIViewController 子类中的 /code> 方法。

对评论的回应:在我的应用程序中,许多页面都有独特的交互功能,因此我编写了一个独特的 UIViewController 子类来管理这些功能。有些页面将具有相同的功能但内容不同。这些只会使用一个 UIViewController 子类的多个实例。我的模型对象将创建这些 UIViewController 子类并用适当的内容填充它们。

换句话说,无需为每个页面编写新的 UIViewController 子类。页面上只有尽可能多的具有独特功能的数量。如果您的页面不执行任何操作,您甚至可以只使用 UIViewController 而无需子类化。

Yep. Rewrite all your UIView subclasses as UIViewController subclasses. I've done it with a few of my projects, and it turns out to be just a little tedious. For my projects I found it easiest to just create a new Xcode project and build the new infrastructure. Then create new UIViewController classes for each of my old UIView classes. Then I copied and pasted most of the code from the old UIView classes into new UIViewController classes. I changed a lot of self to self.view. The life cycle of a UIViewController is a bit more complex than a UIView, so I ended up moving some initialization code from the designated initializer to the viewDidLoad and viewWillAppear methods in my UIViewController subclasses.

Response to comment: In my apps many pages have unique interactive features, so I write a unique UIViewController subclass to manage those features. Some pages will have the same features but different content. These will just use multiple instances of one UIViewController subclass. My model object will make these UIViewController subclasses and populate them with the appropriate content.

In other words, there's no need to write a new UIViewController subclass for every page. Only as many as you have unique functionality on a page. If your page doesn't do anything, you could even just use UIViewController without subclassing.

送舟行 2025-01-14 08:14:45

请查看iOS 5 iPhone UIPageViewController 应用程序示例一文。该章将简要概述页面视图控制器背后的概念以及旨在演示此类实际操作的示例应用程序。

Check out An Example iOS 5 iPhone UIPageViewController Application article. That chapter will provide a brief overview of the concepts behind the page view controller and an example application designed to demonstrate this class in action.

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