在使用 ARC 时,我的旧 UIWebViews 似乎仍然存在,出于某种原因,即使在我退出他们的 UIViewController 之后,它们仍然出现在 OSX Safari 的开发者工具中。
我正在为包含 UIWebView 的 View Controller 分配一个转换,如下所示:
//Create settings view/tabbar
UITabBarController *tabController = [[NoRotateTabBarController alloc] init] ;
StyleViewController *styleTab = [[StyleViewController alloc] initWithNibName"StyleViewController" bundle:nil];
styleTab.tabBarItem.title = @"Style";
styleTab.tabBarItem.image = [UIImage imageNamed"EyeIcon.png"];
NSArray *tabsArray = @[styleTab];
tabController.viewControllers = tabsArray;
prevView = self.window.rootViewController;
[UIView
transitionWithView:self.window
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
self.window.rootViewController = tabController;
[UIView setAnimationsEnabledldState];
}
completion:nil];
我是这样从那种观点中走出来的:
[UIView
transitionWithView:self.window
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
self.window.rootViewController = prevView;
[UIView setAnimationsEnabledldState];
}
completion:nil];
UIWebView (int StyleViewController) 是这样创建的:
@implementation StyleViewController
UIWebView *webView;
//viewDidLoad
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
webView.scalesPageToFit = NO;
webView.scrollView.scrollEnabled = false;
webView.multipleTouchEnabled = false;
webView.alpha = 0;
webView.backgroundColor = [UIColor clearColor];
webView.opaque = false;
@end
但是,我注意到当我在 Safari 中进行检查时,旧的 UIWebViews 似乎在堆积,而旧的 UIWebViews 仍然显示在菜单中。这是 Safari 开发者工具中的错误吗?有没有办法确保我的 UIWebViews 被释放?
问题在于代表。我正在使用 WebViewJavascriptBridge ,并且它对代表做了一些时髦的事情,所以我需要先摆脱它。在我的 viewWillDisappear
选择器中执行此操作可防止它们被保留:
- (void) viewWillDisappearBOOL)animated { /* or dealloc */
[super viewWillDisappear:animated];
_bridge = nil;
//UIWebView #1
[webView removeFromSuperview];
webView.delegate = nil; webView = nil;
//UIWebView #2
[textView removeFromSuperview];
textView.delegate = nil; textView = nil;
}
无论如何,感谢您提供的所有出色答案!
关于iphone - ARC - UIWebView/UIViewController 留在内存中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16347469/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |