简体   繁体   English

viewDidUnload帮助 - iPhone应用程序

[英]viewDidUnload help - iPhone app

I'm having trouble with the new iOS 6. Previously I understood "viewDidUnload". 我在使用新的iOS 6时遇到了麻烦。以前我理解“viewDidUnload”。 It's my understanding that this is now depreciated and I'm having some issues with ending the networks activity indicator. 我的理解是,现在这已经折旧,我在结束网络活动指标方面遇到了一些问题。 Below is my code. 以下是我的代码。 Thanks in advance for your help! 在此先感谢您的帮助!

#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

I think you misunderstand what viewDidUnload is for. 我想你误解了viewDidUnload的用途。 Your code shows nothing to do with hiding the activity spinner in viewDidUnload . 您的代码与viewDidUnload隐藏活动微调器无关。

- (void)viewDidUnload
{
  webview = nil;
  activityindicator = nil;
  searchbar = nil;
  [super viewDidUnload];
}

viewDidUnload was only ever meant for cleaning up retained, replaceable objects when the system had purged your UIViewController's inactive view during a case of low memory. viewDidUnload仅用于在系统内存不足的情况下清除UIViewController的非活动视图时清理保留的可替换对象。

In iOS 6 viewDidUnload is never called, because the system will no longer purge a UIViewController's view in low memory situations, it's up to you to do that if you need too in the didReceiveMemoryWarning callback. 在iOS 6中,从不调用viewDidUnload,因为系统将不再在低内存情况下清除UIViewController的视图,如果你在didReceiveMemoryWarning回调中也需要它,那么你可以这样做。

- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  if ([self isViewLoaded] && self.view.window == nil)
  {
    self.view = nil;
    [self viewDidUnload];
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM