UIWebView: where to load request in tab screen? viewDidLoad or viewDidAppear?
I have a tab bar controller, one tab screen contains a web view, loading a request say google.com, when it is loading(ie before the didload delegate method call of webview), if I switch to another tab and then go back, the spinner is still running but the page is never loaded, I guess viewDidLoad is only called once, so should I put the loading c开发者_运维知识库ode in viewDidAppear, or is there anyway to solve this?
Thanks!
I don't understand why you want to refresh the WebView everytime it appears. But use - (void)viewWillAppear:animated
Edit:
OK, since ive got more info now, i can give you more info!
In your .h:
BOOL *loaded
in your .m:
- (void)viewWillAppear:animated {
if (loaded == NO) {
//load the website
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[loaded setBool:YES];
}
- (IBAction)loadWebsite {
//if the user reloads or loads a new website do this:
[loaded setBool:NO];
//reload, or load the new website
}
To load, or reload your UITableView:
NSString *urlAddress = urltextfield.text;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Clarification: I am setting the BOOL to YES if the View is loaded, so when the webview has finished loading and the user switches to the other tab, and back the WebView doesn't get reloaded. But if the WebView isn't fully loaded the BOOl returns NO, and the WebView will get reloaded! When the WebView gets reloaded or a new Website gets loaded im setting the BOOL to NO, and that loops over and over! Note that BOOls are NO by default.
精彩评论