保留UIWebView,以便稍后再次显示?

发布于 2024-12-17 13:33:20 字数 1015 浏览 4 评论 0原文

如果我想保留一个 UIWebView 以供以后“重用”,可以吗?例如,假设特定站点上的 UIWebView 对您的应用程序很重要,但不是其中的唯一内容。也许该网站需要一段时间才能加载。当用户离开 UIWebView 时,我想保留对 UIWebView 及其内容的引用,因此,如果用户决定重新打开 WebView,它就位于他或她离开的位置。

我已经尝试过这个,但它似乎对我不起作用。在我的情况下,在 iPad 上,有一个部分屏幕 UIWebView,我对其保持强引用,如果用户愿意,我将呈现全屏模式视图并将该 UIWebView 引用插入到合成的 UIWebView 属性中视图控制器。当模态视图进入全屏时,背景只是白色,并且 Web 视图不显示任何内容,即使我保留指针的现有 Web 视图已经有活动。

@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];

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];

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

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

发布评论

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

评论(1

埋葬我深情 2024-12-24 13:33:20

您可以使用 NSCoding 在使用之间归档和取消归档 UIWebView,因为它符合 NSCoding 协议。

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

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