删除父级后,CDVViewController仍在执行JS

时间:2012-09-13 21:13:36

标签: objective-c ios webview automatic-ref-counting cordova

我试图将Cordova CleaverView(CDVViewController)插入从故事板中实例化的UIViewController(SenchaViewController),以呈现基于javascript Sencha的视图。

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

if (![ self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
    self.slidingViewController.underLeftViewController  = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];    
}   

self.view.layer.shadowOpacity = 0.75f;
self.view.layer.shadowRadius = 10.0f;
self.view.layer.shadowColor = [UIColor blackColor].CGColor;


CDVViewController *cdvc = [CDVViewController new];

cdvc.wwwFolderName = @"www";
cdvc.startPage = @"sencha.html";
cdvc.useSplashScreen = NO;


if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{
    cdvc.view.frame = CGRectMake(0, 0, 768, 1004);
} else {
    cdvc.view.frame = CGRectMake(0, 0, 320, 460);
} 

[self.view addSubview:cdvc.view];
[self.view  bringSubviewToFront:self.menuButton];
[self.view  bringSubviewToFront:self.favButton];
cdvc = nil;

NSString *jsSetIdString = [NSString stringWithFormat:@"fetchGuid = function(){return '%@';}", [player valueForKey:@"playerID"]]; 
[[cdvc webView] stringByEvaluatingJavaScriptFromString:jsSetIdString];

[self.view addGestureRecognizer:self.slidingViewController.panGesture];

}

我的问题是在我删除拥有CDVViewController的视图实例的父ViewController(SenchaViewController)之后,CDVViewController没有被释放并且仍然在后台运行,因为我仍然可以在控制台中看到javascript日志记录。我有几个CDVViewController一次全部运行的原因。

这是应用程序添加父视图控制器的方式:

- (void)renderPlayer:(NSNotification*)notification {
SenchaViewController* newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SenchaView"];
NSDictionary *player = notification.object;

// Set active player
if( player != nil && [player valueForKey:@"playerID"] != @"" ){        
    // Attach Player Dictionary to Sencha View
    newTopViewController.player = player;

    // Send it to the top
    CGRect frame = self.slidingViewController.topViewController.view.frame;
    self.slidingViewController.topViewController = newTopViewController;
    self.slidingViewController.topViewController.view.frame = frame;
}

这是如何删除拥有CDVController的Parent View控制器

_topViewController.view removeFromSuperview];
[_topViewController willMoveToParentViewController:nil];
[_topViewController removeFromParentViewController];

我错过了什么吗?我假设ARC会为我释放这个

1 个答案:

答案 0 :(得分:0)

科尔多瓦有一些肮脏的方面,这就是其中之一。删除CDVViewController不足以让它发布。您还必须调用[controller dispose]方法。