2014-04-07 1 views
0

UIWebViewDelegate를 사용하려고하는데 대리자를 자체로 설정할 때 '할당 취소 된 인스턴스로 전송 된 메시지'오류가 발생합니다.retain viewcontroller - 할당 취소 된 인스턴스에 보낸 메시지

실제 오류 : "2014년 4월 7일 22 : 12 : 05.402 AppName[746:60b] -[WebViewController respondsToSelector:]: message sent to deallocated instance 0xa47ae00"

나는 WebViewController 인스턴스가 유지되지 않았기 때문에 이것이 가정

사람이에 대한 올바른 방향으로 날 지점 수 있을까요?

내 구조는하십시오 : RootViewController> WebViewController (위임)> 웹보기

// root.h 
@interface RootViewController : UIViewController 
@property (strong, nonatomic) WebViewController * webViewController; 
@end 

// root.m 

#import "RootViewController.h" 
#import <UIKit/UIKit.h> 
#import "WebViewController.h" 

@interface RootViewController() 

@end 

@implementation RootViewController 

- (void)viewDidLoad 
{ 

    _webViewController = [[WebViewController alloc] init]; 

    [self.view addSubview:_webViewController.view]; 

} 

@end 

// .h 

#import <UIKit/UIKit.h> 

@interface WebViewController : UIViewController <UIWebViewDelegate> 
@property(strong) UIWebView *webView; 
@end 

// .m 

#import "WebViewController.h" 

@interface WebViewController() 
@end 

@implementation WebViewController 

- (void)viewDidLoad 
{ 
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; 
    _webView.delegate = self; 
    NSString *url = @"http://google.com/"; 
    NSURL *nsurl = [NSURL URLWithString:url]; 
    NSURLRequest *nsrequest = [NSURLRequest requestWithURL:nsurl]; 
    [_webView loadRequest:nsrequest]; 
    [self.view addSubview:_webView]; 
} 

-(void)webViewDidStartLoad:(UIWebView *)webView { 
    NSLog(@"ui web view started load"); 
} 
+0

'이 될 것 같지 않습니다 그래서 바르 포인터에 의해 유지되고있다 webViewController' 그것. 나는 한눈에 답을 얻지 못했지만, webView 속성에'nonatomic'을 추가하는 것을 잊었다는 의견을 가지고 있습니다. 거의 확실하게 의도하지 않았습니다. – Dima

+0

설명이없는 내용이있을 수 있으므로 실제 메시지에 세부 정보를 붙여 넣을 수 있습니까? –

+0

@PhillipMills는 귀하의 의견에 대해 덕분에 오류 메시지 – gibo

답변

0

내가 이렇게 같은 루트 뷰 컨트롤러를 설정하지 않았다 :

self.window.rootViewController = rootController; 
1

코드를 loadView에서 viewDidLoad으로 옮기고 loadView으로 전화를 제거하십시오. 보기 컨트롤러가 인스턴스화되어 표시 될 때 loadView이 자동으로 호출되므로 다시 호출하면 웹보기가 두 번 인스턴스화 될 수 있습니다. 워드 프로세서

:

You should never call this method directly. The view controller calls this method when its view property is requested but is currently nil. This method loads or creates a view and assigns it to the view property.

+0

을 추가했지만 변경 사항으로 인해 동일한 오류가 발생합니다. 제안 된 업데이트로 질문을 업데이트했습니다. – gibo