简体   繁体   中英

UIWebView still active after pressing back button

I'm using a Navigationcontroller which pushes a new Viewcontroller containing a Webview every time a link is clicked. One of the URLs has a javascript function, which calls another function every 60 seconds. It works fine, but when I hit the back button once after being on that web view (containing the javascript), the webview stays active and keeps doing the javascript calls, while going back to the previous webview flawlessly. I can see it doing things through NSLog. Why is that and how can I avoid this?

EDIT:

I have declared my subclass of UIWebView in my Viewcontroller like this:

@property (strong, nonatomic) AFXTWebView *wv;

and this is how I instantiate it (in ViewDidLoad):

    [self setWv:[[AFXTWebView alloc] initWithVC:self andURLString:[self.pageConfig objectForKey:xAFXTPageLink]]];

    [self.view addSubview:self.wv];    

    [self.wv loadWebView];

I have also tried setting the webView to nil in viewWillDisappear:

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.wv = nil;
}

You have to use the viewWillAppear & viewWillDisappear methods

-(void)viewWillAppear:(BOOL)animated
{
_webView=[[UIWebView alloc]init];
......//do your stuff
}


-(void)viewWillDisappear:(BOOL)animated
{
[_webView removeFromSuperView];
_webView=nil;
}

在您的viewWillDisappear将空白页面加载到Web视图中。

This sounds like your web view and view controller are not being released, ie you have a leak. You should check your code for any unreleased retained/strong references to your view controller or web view.

-(void)viewDidDisappear:(BOOL)animated
{
  [super viewDidDisappear:animated];
  [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM