gpt4 book ai didi

iphone - viewDidUnload 帮助 - iPhone 应用程序

转载 作者:行者123 更新时间:2023-11-28 22:48:05 25 4
gpt4 key购买 nike

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

最佳答案

我认为您误解了 viewDidUnload 的用途。您的代码显示与在 viewDidUnload 中隐藏事件微调器无关。

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

viewDidUnload 仅用于在内存不足的情况下系统清除 UIViewController 的非事件 View 时清理保留的可替换对象。

在 iOS 6 中,viewDidUnload 永远不会被调用,因为系统将不再在内存不足的情况下清除 UIViewController 的 View ,如果您也需要在 didReceiveMemoryWarning 回调中执行此操作,则由您决定。

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

关于iphone - viewDidUnload 帮助 - iPhone 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12681568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com