UIWebView가있는 UIViewController 하위 클래스가 있습니다. 뷰의 하위 뷰인 웹 뷰를 추가하고 dealloc에서이를 해제합니다. 관련 코드는 다음과 같습니다.UIWebView로 인해 충돌이 발생합니다.
#import "MediaVC.h"
@implementation MediaVC
@synthesize file, repository, server, delegate;
- (void)viewDidLoad {
[super viewDidLoad];
webView = [[UIWebView alloc] initWithFrame:[[self view] bounds]];
[webView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[webView setScalesPageToFit:YES];
[webView setMultipleTouchEnabled:YES];
[[self view] addSubview:webView];
[self displayFile];
[flex release];
[buttonDone release];
[buttonAction release];
}
- (void)displayFile {
if (!mimeString) {
[webView loadData:nil
MIMEType:nil
textEncodingName:nil
baseURL:nil];
[SVProgressHUD dismissWithError:@"Can't display this file." afterDelay:2];
} else {
[[DataCenter sharedInstance] getDataForFile:file
server:server
repository:repository
isThumb:NO
completion:^(NSData *data) {
NSString *filenamePath =[NSString stringWithFormat:@"temp.%@", [[file path] pathExtension]];
NSString *docDir = [DataCenter getDocumentsDirectoryPath];
NSString *fullPath = [docDir stringByAppendingPathComponent:filenamePath];
[data writeToFile:fullPath atomically:YES];
[webView loadData:data
MIMEType:[DataCenter mimeTypeForFile:file]
textEncodingName:nil
baseURL:nil];
if (!data) {
[SVProgressHUD dismissWithError:@"Error!"];
} else {
[SVProgressHUD dismiss];
}
} progress:^(float progress) {
[SVProgressHUD setFloat:progress];
}];
}
}
- (void)dealloc {
[buttonNext release];
[buttonBack release];
//[webView release]; ---CRASH HAPPENS IF I UNCOMMENT THIS LINE
[super dealloc];
}
@end
[super dealloc];에서 앱이 다운됩니다. NSZombieEnabled 있고 "deallocated 인스턴스에 보낸 오류 ...."관한 어떤 오류도주지 않습니다. 내가 찾은 것은 내가을 언급하면 충돌이 발생하지 않는다는 것이다. 확인하고 UIWebView를 한 번만 할당하고 한 번 릴리스합니다.
업데이트 아래에서 전체 클래스를 찾으십시오.
#import "MediaVC.h"
#import "DataCenter.h"
#import "SVProgressHUD.h"
#import "File.h"
@implementation MediaVC
@synthesize file, repository, server, delegate;
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *buttonDone = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(done)];
UIBarButtonItem *buttonAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(action:)];
buttonNext = [[UIBarButtonItem alloc] initWithTitle:@"Next"
style:UIBarButtonItemStyleDone
target:self
action:@selector(next)];
buttonBack = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleDone
target:self
action:@selector(back)];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
[[self navigationItem] setLeftBarButtonItem:buttonDone];
[[self navigationItem] setRightBarButtonItem:buttonAction];
[[self navigationController] setToolbarHidden:NO];
[self setToolbarItems:[NSArray arrayWithObjects:buttonBack, flex, buttonNext, nil] animated:YES];
webView = [[UIWebView alloc] initWithFrame:[[self view] bounds]];
[webView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[webView setScalesPageToFit:YES];
[webView setMultipleTouchEnabled:YES];
[[self view] addSubview:webView];
[self displayFile];
[flex release];
[buttonDone release];
[buttonAction release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)done {
[delegate doneMediaVC:self];
}
- (void)action:(id)button {
NSString *filenamePath = [file path];
NSString *docDir = [DataCenter getDocumentsDirectoryPath];
NSString *fullPath = [docDir stringByAppendingPathComponent:filenamePath];
NSURL *url = [NSURL fileURLWithPath:fullPath];
UIDocumentInteractionController *c = [UIDocumentInteractionController interactionControllerWithURL:url];
BOOL success = [c presentOpenInMenuFromBarButtonItem:buttonBack animated:YES];
if (!success) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"An application cannt be found to open this file"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alertView show];
[alertView release];
}
}
- (void)displayFile {
[self setTitle:[file name]];
[SVProgressHUD showInView:[[self navigationController] view]
status:@"Loading..."
networkIndicator:YES
progress:YES];
NSString *mimeString = [DataCenter mimeTypeForFile:file];
if (!mimeString) {
[webView loadData:nil
MIMEType:nil
textEncodingName:nil
baseURL:nil];
[SVProgressHUD dismissWithError:@"Can't display this file." afterDelay:2];
} else {
[[DataCenter sharedInstance] getDataForFile:file
server:server
repository:repository
isThumb:NO
completion:^(NSData *data) {
NSString *filenamePath =[NSString stringWithFormat:@"temp.%@", [[file path] pathExtension]];
NSString *docDir = [DataCenter getDocumentsDirectoryPath];
NSString *fullPath = [docDir stringByAppendingPathComponent:filenamePath];
[data writeToFile:fullPath atomically:YES];
[webView loadData:data
MIMEType:[DataCenter mimeTypeForFile:file]
textEncodingName:nil
baseURL:nil];
if (!data) {
[SVProgressHUD dismissWithError:@"Error!"];
} else {
[SVProgressHUD dismiss];
}
} progress:^(float progress) {
[SVProgressHUD setFloat:progress];
}];
}
if (![delegate canGoNext:self currentFile:file]) {
[buttonNext setEnabled:NO];
} else {
[buttonNext setEnabled:YES];
}
if (![delegate canGoPrevious:self currentFile:file]) {
[buttonBack setEnabled:NO];
} else {
[buttonBack setEnabled:YES];
}
}
- (void)back {
[self setFile:[delegate getPreviousFileForMediaVC:self currentFile:file]];
[self displayFile];
}
- (void)next {
[self setFile:[delegate getNextFileForMediaVC:self currentFile:file]];
[self displayFile];
}
- (void)dealloc {
[buttonNext release];
[buttonBack release];
//[webView release];
[super dealloc];
}
@end
감사 : 내가 말했듯이, 어쩌면 너희들 뭔가 발견, 거기에 관련 아니라 그 클래스의 많은 그리고 나는 거기에 어떤 문제를 찾을 수 없습니다!
webview 변수의 할당 및 릴리스에는 아무런 문제가 없습니다. 어쩌면 webview에 매핑 된 유지 된 속성을 만들었 을까요? 그렇지 않은 경우 다른 것이 충돌을 일으킬 수 있어야합니다. –
@PhilippeLeybaert는 누락 된 코드의 양을보고 실제 코드에 많은 오류가있을 수 있습니다. – mvds
그 이유는 변수의 할당/해제에 아무런 문제가 없다고 말한 것이고 다른 것은 아마도 문제를 일으키는 것입니다. –