开发者

UIWebView won't load new URL

I have a UITableView that displays peoples names of whatever department is chosen. When you then select a person in the TableView, it loads a detail page with labels with all their contact info; then at the bottom it loads their website in a smaller UIWebView.

If you choose a person, view their info, go back, then choose another person in that same department, the UIWebView does not reload the new selected person's website, it remains on the site of the person whom was first selected.

I have tried all night to get this working; I am sure its something simple.

I have tried setting the webView to nil, and releasing it in the viewDidDisappear and viewWillDisappear (the ones that get called when you go back to the list of people after viewing one).

I have this set up as a UINavigationController.

The labels for the selected person details all update for the selected person, but the UIWebView just doesn't want to reload. Any help appreciated!!

EDIT Sorry I forgot to add the code, it was way too late when I posted this lol. But here where all my labels and things get updated (I took those lines out to clean it up on 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 viewDidDisapp开发者_运维知识库ear:animated];
    [webView release];
    webView = nil;
    url = nil;
}


Remove your code in viewWillDisappear and viewDidDisappear, and try this:

-(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 you switch tabs (if you have any) or when the app comes to the foreground. For that reason, I prefer to load the url when I push 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 that helps!


spit the url to your console. it sounds like you may be passing the same url.
but yeah fluchtpunkt is right, lets see your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜