• <bdo id='IooPs'></bdo><ul id='IooPs'></ul>

    <tfoot id='IooPs'></tfoot>

    1. <small id='IooPs'></small><noframes id='IooPs'>

      <i id='IooPs'><tr id='IooPs'><dt id='IooPs'><q id='IooPs'><span id='IooPs'><b id='IooPs'><form id='IooPs'><ins id='IooPs'></ins><ul id='IooPs'></ul><sub id='IooPs'></sub></form><legend id='IooPs'></legend><bdo id='IooPs'><pre id='IooPs'><center id='IooPs'></center></pre></bdo></b><th id='IooPs'></th></span></q></dt></tr></i><div id='IooPs'><tfoot id='IooPs'></tfoot><dl id='IooPs'><fieldset id='IooPs'></fieldset></dl></div>
      <legend id='IooPs'><style id='IooPs'><dir id='IooPs'><q id='IooPs'></q></dir></style></legend>

      1. 在 UINavigationController 上推送许多视图控制器时出现内存问题

        Memory problems when pushing many view controllers on UINavigationController(在 UINavigationController 上推送许多视图控制器时出现内存问题)

            <tfoot id='XGtXI'></tfoot>
              <tbody id='XGtXI'></tbody>
              • <i id='XGtXI'><tr id='XGtXI'><dt id='XGtXI'><q id='XGtXI'><span id='XGtXI'><b id='XGtXI'><form id='XGtXI'><ins id='XGtXI'></ins><ul id='XGtXI'></ul><sub id='XGtXI'></sub></form><legend id='XGtXI'></legend><bdo id='XGtXI'><pre id='XGtXI'><center id='XGtXI'></center></pre></bdo></b><th id='XGtXI'></th></span></q></dt></tr></i><div id='XGtXI'><tfoot id='XGtXI'></tfoot><dl id='XGtXI'><fieldset id='XGtXI'></fieldset></dl></div>

              • <small id='XGtXI'></small><noframes id='XGtXI'>

                  <bdo id='XGtXI'></bdo><ul id='XGtXI'></ul>
                  <legend id='XGtXI'><style id='XGtXI'><dir id='XGtXI'><q id='XGtXI'></q></dir></style></legend>
                • 本文介绍了在 UINavigationController 上推送许多视图控制器时出现内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为 iPad 制作一本交互式书籍,并且正在使用 UINavigationController 来实现页面和下一个页面之间的导航.当用户翻页时,下一页被推送到导航堆栈的顶部.

                  I'm making an interactive book for the iPad and am using UINavigationController to implement the navigation between a page and the next. When a user turns the page, the next page is pushed on top of the navigation stack.

                  我现在进入应用程序的第 15 页,当我尝试从第 14 页转到第 15 页时,应用程序崩溃了.控制台中没有错误消息,设备的崩溃日志中也没有任何内容.

                  I'm now 15 pages into the app, and the app crashes when I try to go from page 14 to page 15. No error message in the console, nothing in the device's crash logs neither.

                  情节提要中每个视图控制器的场景都有 UIImageViews 显示 5MB 到 20MB 之间的图像.视图控制器的 viewDidLoad 方法只被调用一次.所有应用程序资产的总大小低于 200B.我正在使用ARC.

                  Each view controller's scene in the storyboard has UIImageViews displaying images that are between 5MB and 20MB. The view controllers' viewDidLoad method is called just once. The total size of all the app's assets is below 200B. I'm using ARC.

                  我使用 Instruments 的 Memory Monitor 运行了该应用程序.每次翻页,应用程序的Real Memory消耗增加约80MB,达到800MB时崩溃(设备为iPad 3).

                  I've ran the app using Instruments' Memory Monitor. The app's Real Memory consumption increases by about 80MB every time a new page is turned, and crashes when it reaches 800MB (the device is an iPad 3).

                  • 为什么这么大的内存消耗?这是因为 Storyboard 场景中的 UIImageView 缓存了图像吗?

                  • Why such an enormous memory consumption? Is this because the UIImageView in the Storyboard's scenes cache the images?

                  使用UINavigationController 和 ARC?

                  我尝试在视图控制器的 viewDidDisappear: 方法中将所有视图控制器的子视图设置为 nil,但内存消耗保持不变.

                  I tried adding setting all the view controller's subviews to nil in the view controllers' viewDidDisappear: method, but memory consumption stayed the same.

                  推荐答案

                  当您使用 UINavigationController 时,您推送的每个 ViewController 都会永久保留在内存中(嗯,直到您的应用退出),除非您的用户按下该特定 ViewController 上的后退按钮.它保留了一堆 ViewController - 可见的在顶部.

                  When you use a UINavigationController, each ViewController you push stays in memory forever (well, until your app exits) unless your user presses the back button on that particular ViewController. It keeps a stack of ViewControllers - with the visible one at the top.

                  所以简单的答案是不要为此使用 UINavigationController.我建议构建自己的 ViewController 来知道"下一页和上一页,并在需要时手动加载和删除它们.这样你可以确保你一次只有一个页面在内存中(除了在过渡期间 - 也许你可以使用这个动画来进行过渡 http://cocoacontrols.com/platforms/ios/controls/xbpagecurl).

                  So the simple answer is don't use a UINavigationController for this. I'd suggest building your own ViewController that 'knows' which is the next and previous pages and manually loads and removes them as and when required. This way you can ensure that you only have one page in memory at once (except for during the transitions - maybe you could use this animation for the transitions http://cocoacontrols.com/platforms/ios/controls/xbpagecurl).

                  这篇关于在 UINavigationController 上推送许多视图控制器时出现内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)
                  How to show the progress of copying a large file in iOS?(如何在iOS中显示复制大文件的进度?)

                    <legend id='1L8DS'><style id='1L8DS'><dir id='1L8DS'><q id='1L8DS'></q></dir></style></legend>

                        <tbody id='1L8DS'></tbody>

                        <tfoot id='1L8DS'></tfoot>

                        <small id='1L8DS'></small><noframes id='1L8DS'>

                        • <bdo id='1L8DS'></bdo><ul id='1L8DS'></ul>
                          <i id='1L8DS'><tr id='1L8DS'><dt id='1L8DS'><q id='1L8DS'><span id='1L8DS'><b id='1L8DS'><form id='1L8DS'><ins id='1L8DS'></ins><ul id='1L8DS'></ul><sub id='1L8DS'></sub></form><legend id='1L8DS'></legend><bdo id='1L8DS'><pre id='1L8DS'><center id='1L8DS'></center></pre></bdo></b><th id='1L8DS'></th></span></q></dt></tr></i><div id='1L8DS'><tfoot id='1L8DS'></tfoot><dl id='1L8DS'><fieldset id='1L8DS'></fieldset></dl></div>