开发者

How do i update webview from settings preferences

开发者 https://www.devze.com 2023-03-27 11:11 出处:网络
very simple question.I have an app with a single view (webview) that loads a url.The app has a settings bundle attached to it with one field asking for a string. Here is the code in my viewcontroller:

very simple question. I have an app with a single view (webview) that loads a url. The app has a settings bundle attached to it with one field asking for a string. Here is the code in my viewcontroller:

-(void)viewDidLoad{

[super viewDidLoad];

   NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
   NSString *settingString = [prefs stringForKey:@"name_preference"];
   [pr开发者_StackOverflow中文版efs synchronize];
   [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.stackoverflow.com/%@", settingString]]]];

}

So Far So good right. It takes the string from settings and concatenates the end of the url and all is well. when i run in the simulator i have to close the sim everytime to update the view if i change the string in settings. Is there somewhere else i should put this code instead of "viewDidLoad"? I want my webview to update everytime i re-open my app from settings. Thanks for all of your help....


You can put it in viewDidAppear (in the vc) or applicationDidEnterForeground in your app delegate.

The problem you're having is when you 'launch' the app by tapping it on the home screen, you're actually just using iOS's multitasking to switch back to it (it never quit).


What Alex said will work. But Apple will never accept an app with only one UIWebView. I hope there's more to your app if you're hoping to publish it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号