在UIWebView中加载PDF时出现内存警告

时间:2011-11-04 18:33:21

标签: ios pdf xcode4 uiwebview

我在一个应用程序中有7个ViewControllers,其中一个将本地PDF加载到UIWebView中。初始加载没有问题,但如果我离开ViewController并回到它,在第二次或第三次我在iPad上调试时收到“收到内存警告”(我在模拟器中没有遇到过这个问题,但是这并不意味着我最终不会得到它)。我已经确保case / caps与文件和我的代码一致,并且我没有得到构建错误或警告。我被告知有关xcode4需要@ property / @ synthesize / dealloc的混合内容,所以无论有没有,我都尝试过,结果没有改变。

这是我的.h文件

#import <UIKit/UIKit.h>

@interface Article6 : UIViewController {
    IBOutlet UIWebView *webview;
}

@end

这是我的.m文件

#import "Article6.h"

@implementation Article6


- (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.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"mfa" ofType:@"pdf" inDirectory:NO];
    NSLog(@"path: %@",path);
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];

}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}

@end

我正在使用故事板中的滑动手势,以及常规按钮,这两个segues都会出现此错误。是的,所有的网点都是连接的。

2 个答案:

答案 0 :(得分:0)

在viewDidUnload方法中查看您自己的评论。这是您需要发布的地方,您每次加载视图时都会创建一个新视图。所以当你卸载时释放它。我猜每次关闭webview时都不会调用deAlloc。

要确保我只是使用一些日志来查看您的保留计数,并确保您保留它。祝你好运!

答案 1 :(得分:0)

NSString *path = [[NSBundle mainBundle] pathForResource:@"mfa" ofType:@"pdf" inDirectory:nil];
相关问题