在Settings.bundle
中,我有一个标识为url_preference
的文本输入。当设置被更改时更新UIWebView
使用ViewController.h
,ViewController.m
,和我的故事板我有一个UIWebView
设置显示从设置的URL:
- (void) updateBrowser {
NSString *fullURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"url_preference"];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_EmbeddedBrowser loadRequest:requestObj];
}
这工作。
但是,如果更改了设置中的URL,则UIWebView
不会更新以反映新的URL。
通过禁止应用程序在后台运行,解决了未反映更新的URL的问题。但是,会出现一个新问题:如果“设置”中的URL保留为,则不会保留会话。 UIWebView
只应在url_preference
更改时更新。
我一直在尝试使用applicationWillEnterForeground
在AppDelegate.m
迫使UIWebView
重装,但我有麻烦了。
在ViewController中,我可以运行:
- (void)viewDidLoad {
[self updateBrowser];
}
但是当我尝试运行在App代表同样的事情时不更新:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
ViewController *vc = [[ViewController alloc]init];
[vc updateBrowser];
}
(我还包括- (void) updateBrowser;
在ViewController.h
,并且#import "ViewController.h"
在AppDelegate.m
谢谢。
非常感谢你,马特!这很棒! – bookcasey