UIWebView does not load new URL

I have a UITableView that displays the names of people in any department. When you then select a person in TableView, it loads a detailed page with labels with all their contact information; then below it loads its website in a smaller UIWebView.

If you select a person, view their information, return, then select another person in the same department, UIWebView will not reload the newly selected website, it remains on the site of the person who was first selected.

I tried all night for this to work; I am sure this is something simple.

I tried setting webView to nil and freeing it in viewDidDisappear and viewWillDisappear (those that get called when you return to the list of people after viewing).

I have this configured as a UINavigationController.

Labels for the selected person indicate all updates for the selected person, but UIWebView just does not want to restart. Any help is appreciated!

EDIT Sorry I forgot to add the code, it was too late when I published this LOL. But here, where all my shortcuts and things are updated (I took these lines to clear them here).

-(void)viewWillAppear:(BOOL)animated { NSLog(@"willAppear"); [[self navigationItem] setTitle:[selectedPerson professorLName]]; url = [[NSURL alloc] initWithString:[selectedPerson departmentWebsite]]; NSLog(@"%@", url); req = [[NSURLRequest alloc] initWithURL:url]; [webView loadRequest:req]; webView.scalesPageToFit = YES; } - (void)viewWillDisappear:(BOOL)animated { NSLog(@"willDis"); [super viewWillDisappear:animated]; [webView release]; webView = nil; url = nil; } - (void)viewDidDisappear:(BOOL)animated { NSLog(@"didDisappear"); [super viewDidDisappear:animated]; [webView release]; webView = nil; url = nil; } 
+4
source share
2 answers

Remove the viewWillDisappear and viewDidDisappear and try the following:

 -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:selectedPerson.departmentWebsite]]]; } 

Keep in mind that if you put this in -viewWillAppear , the page will reload when the tabs switch (if any) or when the application comes to the forefront. For this reason, I prefer to load the URL when I click the detail view controller:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SimpleWebViewController* detailViewController = [[SimpleWebViewController alloc] initWithNibName:@"SimpleWebView" bundle:nil]; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]]; [detailViewController release]; } } 

Hope this helps!

+2
source

move the url to the console. it looks like you can pass the same URL.
but yes fluchtpunkt is right, let's see your code.

0
source

Source: https://habr.com/ru/post/1343130/


All Articles