0

我在调用此自定义刷新时遇到无法关闭 CDVViewController 的问题,它会在后台保持加载并加载一个新的导致内存泄漏/高内存使用的新的。我尝试对 webView、子视图、CDVViewController、ChildViewController 使用 release 和 removeFromSuperview,但它们都不起作用。我正在通过 Storyboard 运行选项卡栏控制器,(我必须调用 CDVViewController 作为子视图的另一个原因)当我通过 safari 使用网络检查器时,我可以看到在该选项卡上建立的页面,当我在另一个选项卡上刷新时(不使用 CDVViewController/phonegap)它工作正常。任何帮助深表感谢。

所以这是我的 .h

#import <UIKit/UIKit.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <Cordova/CDVViewController.h>


@interface ThirdViewController : CDVViewController <UIWebViewDelegate>
{
  IBOutlet CDVViewController *webView;
  IBOutlet UIActivityIndicatorView *activityind;
}
- (IBAction)Refresh:(id)sender;


@end

还有我的.m

@interface ThirdViewController ()
@end
@implementation ThirdViewController


- (void)viewDidLoad
{
  webView = [CDVViewController new];
  webView.startPage = @"MYWEBSITE";   
    [self addChildViewController:webView];
    [self.webView addSubview:webView.view];

    webView.view.frame = CGRectMake(0, 0, 0, 0);
    [activityind startAnimating];
    [self.webView addSubview: activityind];
    [self CustomActivity];
}


-(void) CustomActivity
{
    if ([webView.reference isEqualToString:@"TRUE"]){   //webView.reference is something I added into phonegap CDVViewController so that I am able to see when it is being loaded/used to load the custom activity/activity ind to work.
       [activityind removeFromSuperview];
    }else{
       [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(CustomActivity) userInfo:nil repeats:NO];
    }
}

- (IBAction)Refresh:(id)sender {

    webView = [CDVViewController new];              
    webView.startPage = @"MYWEBSITE"; 

    [self addChildViewController:webView];
    [self.webView addSubview:webView.view];


    webView.view.frame = CGRectMake (0,0,self.view.frame.size.width,(self.view.frame.size.height -44));
    [activityind startAnimating];
    [self.webView addSubview: activityind];
    [self CustomActivity];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {}
- (void)webViewDidFinishLoad:(UIWebView *)subview {}
- (void)loading {}
- (void)didReceiveMemoryWarning{[super didReceiveMemoryWarning];}

@end
4

1 回答 1

0

找到了解决方案,我不得不实现 [webView.webView reload];

- (IBAction)Refresh:(id)sender {

[webView.webView reload];

}
于 2013-08-14T14:38:28.433 回答