【发布时间】:2012-03-15 18:46:37
【问题描述】:
我有一个UIViewController,其中包含一个UIWebView。
我使用 UIViewController 中的 UIWebview 登录到一个网站说 facebook,然后我单击完成,这会关闭视图控制器,我想这将释放视图控制器。但是当我再次打开 UIWebview 时(没有退出应用程序,甚至在终止应用程序后),网页在加载网络视图后仍然登录到 Facebook。我应该如何释放 Web 视图,以便每次单击完成并返回 Web 视图时,Web 视图将始终像“全新”而不登录到我以前登录的任何网站。
- (void)viewDidLoad{
NSLog(@"webView viewDidLoad called");
appDelegate = (LoginDBAppDelegate *)[[UIApplication sharedApplication] delegate];
loginObj = [appDelegate.loginArray objectAtIndex:currentSelectedRow];
myWebView.delegate = self;
[super viewDidLoad];
[self showWebView];
}
-(void)showWebView{
NSLog(@"webView showWebView called");
NSURL *url = [NSURL URLWithString:loginObj.loginURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
}
-(IBAction)done_Clicked:(id)sender{
NSLog(@"webView Done_Clicked");
//dismiss the controller
[self.navigationController dismissModalViewControllerAnimated:YES];
}
-(void)dealloc{
[myWebView release];
myWebView.delegate = nil;
[activity release];
[urlTextField release];
[super dealloc];
}
我试过了,但是没用:
-(IBAction)done_Clicked:(id)sender{
NSLog(@"webView Done_Clicked");
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[myWebView stringByEvaluatingJavaScriptFromString:@"var body=document.getElementsByTagName('body')[0];body.style.backgroundColor=(body.style.backgroundColor=='')?'white':'';"];
[myWebView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"];
//dismiss the controller
[self.navigationController dismissModalViewControllerAnimated:YES];
}
我也试过了,没有成功:
- (void) viewDidDisappear:(BOOL)animated {
NSLog(@"webView viewDidDisappear called");
[super viewDidDisappear:animated];
[self.myWebView removeFromSuperview];
self.myWebView.delegate = nil;
self.myWebView = nil;
[myWebView release];
}
【问题讨论】:
标签: ios caching memory-management uiwebview