0
votes

If I want to retain a UIWebView for "reuse" later, is it possible? For instance, say that UIWebView on a specific site is important to your app, but not the only thing in it. Maybe the website takes awhile to load. When the user navigates away from the UIWebView, I would like to keep a reference to the UIWebView and its contents, so if the user decides to reopen the webview, it's exactly where he or she left it.

I've tried this and it doesn't seem to work for me. In my situation, on the iPad, there is a partial screen UIWebView that I'm keeping a strong reference to, and if the user desires, I'm presenting a full screen modal view and inserting that UIWebView reference into a synthesized UIWebView property of the View Controller. When the modal view comes in full screen, the background is just white and the webview is not displaying anything, even though the existing webview that I'm keeping a pointer for has already had activity.

@interface FullScreenWebView : UIViewController
@property (nonatomic,strong) IBOutlet UIWebView *theWebView;

@interface HalfScreenWebView : UIViewController
@property (nonatomic,strong) IBOutlet UIWebView *aWebView;

//in some other class, pretend halfscreenWebView is an object representing HalfScreenWebView
UIWebView *existingWebView = halfscreenWebView.aWebView;
FullScreenWebView *full = [[FullScrenWebView alloc] initWithNibName:@"FullScreenWebView" bundle:nil];
full.modalPresentationStyle = UIModalPresentationStyleFullScreen;
full.theWebView = existingWebView;
[self presentModalViewController:full animated:YES];
1

1 Answers

2
votes

You can use NSCoding to archive and unarchive the UIWebView between uses since it conforms to the NSCoding protocol.