2010-04-03 10 views
0

프로그래밍 방식으로 뷰 컨트롤러를 밀고 WebView 및 사용자 정의 직사각형 둥근 버튼을 오른쪽 아래 왼쪽 구석에 뷰에 밀어 넣었습니다.푸시보기 컨트롤러에서 맞춤 뒤로 버튼 클릭 이벤트

-(void)loadView { 


     CGRect frame = CGRectMake(0.0, 0.0, 480, 320); 
    WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease]; 
    WebView.backgroundColor = [UIColor whiteColor]; 
    WebView.scalesPageToFit = YES; 
    WebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); 
    WebView.autoresizesSubviews = YES; 
    WebView.exclusiveTouch = YES; 

    WebView.clearsContextBeforeDrawing = YES; 

self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 
self.roundedButtonType.frame = CGRectMake(416.0, 270.0, 44, 19); 
[self.roundedButtonType setTitle:@"Back" forState:UIControlStateNormal]; 
self.roundedButtonType.backgroundColor = [UIColor grayColor]; 
[self.roundedButtonType addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside]; 

self.view = WebView; 

[self.view addSubview: self.roundedButtonType ]; 
[WebView release]; 


} 

내비게이션의 뒤로 버튼으로 추가 한 동작입니다. EXC_BAD_ACCESS 메시지 : 뒤로 버튼 다음 이전 뷰를 보여주고 클릭하지만 응용 프로그램이 해당 뷰에 갇혀와 GDB는 프로그램이 신호를받은 보여주고있어 여기

-(void)back:(id)sender{ 
[self.navigationController popViewControllerAnimated:YES]; 
} 

-(void)viewDidUnload{ 
self.WebView = nil; 
self.roundedButtonType = nil; 
} 

-(void)dealloc{ 
[roundedButtonType release]; 
[super dealloc]; 
} 

.

이 문제를 어떻게 해결합니까?

WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease]; 

하지만 당신에게 -release를 다시를 : 당신은 -autorelease

감사합니다,

답변

0

여기 WebView을 거라고!

[self.view addSubview: self.roundedButtonType ]; 
[WebView release]; 

릴리스 중 하나를 제거하십시오. @property(assign,...)로 선언

self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 

roundedButtonType하지 않는 한 또한


는, 당신은 -retain 메시지를 보낼 필요가 없습니다. self.roundedButtonType에 대한 모든 호출은 무료가 아니므로 self.roundedButtonType에 할당하기 전에 프레임, 제목 등을 설정하는 것이 좋습니다.

+0

감사합니다, Kenny WebView에 autorelease 중 하나를 제거했으며 그 경우에는 문제가 없습니다. [WebView release]가 http 요청을 해제하거나 WebView에서 데이터를 언로드하고 URL에 대한 연결이 활성화되어 있습니까? 할당하기 전에 설정 프레임과 제목도 알아 보겠습니다. Thasnk – TechFusion

+0

@Tech : 웹보기가 '-dealloc'되었을 때 웹보기가 소유 한 모든 항목이'-release'됩니다 (release ≠ deallocate를 기록하십시오). 귀하의 경우'self'는'self.view'에 지정할 때 웹보기를'-retain' 할 것이므로'-release''ing하면 연결을 죽이지 않습니다. – kennytm

+0

Hello Kenny, ViewDidUnload()에서도 self.WebView = nil을 만들고 있습니다. 그래서 내가 dealloc 작업에 다음을 추가해야 연결을 죽일? - (void) dealloc { [super dealloc] [self.WebView dealloc] // 맞습니까? } 감사합니다. – TechFusion

관련 문제