Here is some context to my issue.... using iOS 5 as the target for my iPhone app with ARC on:
I have an app that has a UINavigationController
. There are multiple view on the stack that get pushed to the top. The final view that is shown is a UIWebView
with Google Images website, and users can select an image and have it sent back to a UIImageView
on the view previous in the nav stack. Users can then hit Back and then on the previous view to that hit a Save UIBarButton
to save the image locally on their device. Here is what the stack looks like:
MainView -> DetailsView (with Save
UIBarButton
in upper right) -> ImageDisplayView -> WebView (with Google Images website loaded)
The problem is, when a user selects a large image from Google Images (lets say a 5MB image) using the View Full Image button on Google Images Mobile, a memory warning is thrown and the views below it are released. So when a user goes back to the DetailsView with the Save button, the Save button is now gone. This is because didReceiveMemoryWarning
is called.
So my questions are....
Why is a memory warning called when displaying a 5MB image in an embedded UIWebView?
How do I prevent the memory warning from causing issues (like dropping UIBarButton views) lower in my navigation stack?
Are there any tips/tricks that anyone knows to get full sized images properly from Google Images mobile within an iPhone app?
To try this problem for yourself, create a UIWebView
in a blank app and just load Google Images website into it. Install it on your device (3GS or lower will make the problem appear quicker) and just load full images into and out of the browser... you'll eventually get the warning in your debug console.
Check out the iOS documentation for "Responding to Low-Memory Warnings in iOS" where it states "View controllers automatically purge any views that are currently offscreen" Also look at "The View Controller Life Cycle". Your view controllers will get viewWillUnload: and viewDidUnload: messages. You'll have to recreate the views using, for example loadView (if not using Storyboards), when they are next needed.
Specifically answering your questions:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.