0

我在使用新的 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
4

1 回答 1

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];
   }
}
于 2012-10-01T21:54:20.120 回答