我在使用新的iOS 6时遇到了问题。之前我理解“viewDidUnload”。我的理解是,现在这已经折旧,我在结束网络活动指标方面遇到了一些问题。以下是我的代码。在此先感谢您的帮助!
#import "MapViewController.h"
@implementation MapViewController
@synthesize webview, url, activityindicator, searchbar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization.
}
return self;
}
- (void)viewDidLoad
{
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webview.delegate = self;
activityindicator.hidden = TRUE;
[webview performSelectorOnMainThread:@selector(loadRequest:) withObject:requestObj waitUntilDone:NO];
[super viewDidLoad];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
activityindicator.hidden = TRUE;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityindicator stopAnimating];
NSLog(@"Web View started loading...");
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
activityindicator.hidden = FALSE;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[activityindicator startAnimating];
NSLog(@"Web View Did finish loading");
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
webview = nil;
activityindicator = nil;
searchbar = nil;
[super viewDidUnload];
}
- (void)dealloc {
[url release];
[super dealloc];
}
@end
答案 0 :(得分:2)
我认为你误解了viewDidUnload
的用途。您的代码与隐藏viewDidUnload
中的活动微调器没有任何关系。
- (void)viewDidUnload
{
webview = nil;
activityindicator = nil;
searchbar = nil;
[super viewDidUnload];
}
viewDidUnload
仅用于在系统内存不足的情况下清除UIViewController的非活动视图时清理保留的可替换对象。
在iOS 6中,从不调用viewDidUnload,因为系统将不再在低内存情况下清除UIViewController的视图,如果您需要didReceiveMemoryWarning
回调,则由您自己执行。
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if ([self isViewLoaded] && self.view.window == nil)
{
self.view = nil;
[self viewDidUnload];
}
}