2011-01-22 3 views
0

친구들. iphone을 처음 사용했습니다. 문제가 발생했습니다 .Uiimageview는 ... 코드를 공개 할 수 없습니다.아이폰 UIIMAGEVIEW는 출시 할 수 없습니까?

#import <UIKit/UIKit.h> 
@interface imageNavView : UIImageView { 

    int index; 
} 
@property int index; 

@end 
#import "imageNavView.h" 


    @implementation imageNavView 
    @synthesize index; 
    - (id)initWithFrame:(CGRect)frameRect{ 
     self = [super initWithFrame:frameRect]; 
     if (self) { 
      // Custom initialization. 
      self.userInteractionEnabled=YES; 
      self.multipleTouchEnabled=YES; 
      self.opaque=YES; 
      self.autoresizingMask=(UIViewAutoresizingFlexibleHeight| 
            UIViewAutoresizingFlexibleWidth| 
            UIViewAutoresizingFlexibleRightMargin 
            |UIViewAutoresizingFlexibleLeftMargin 
            |UIViewAutoresizingFlexibleTopMargin 
            |UIViewAutoresizingFlexibleBottomMargin); 
      index=0; 
     } 
     return self; 
    } 

    - (void)dealloc { 
     NSLog(@"before image dealloc %i",[self retainCount]);-------- log is 1 
      [super dealloc]; 
     NSLog(@"after image dealloc %i",[self retainCount]);-------- log is 1,why itn't bad access? 
    } 


    @end 

이유는 두 번째 ([자기 retainCount] "이미지 할당 해제의 %의 난 후에"@) NSLog 로그 않는다; 1이면 잘못된 액세스가 아니므로 이미지 뷰가 해제되지 않습니다. 나는 이해할 수 없다, 어떤 가능한 방법이라도 이것이 일어날 수 있는가? ... 조언은 감사 할 것이다.

답변

0

dealloc은 시스템이 객체를 해제하는 동안 콜백 메소드입니다. (수신기 유지할 수있는 해제 메시지 결과가 0이되는 경우)

다음의 설명은

대신 객체의 할당 해제의 방법은 방출 NSObject의 프로토콜 방식을 통해 간접적으로 호출되는, 할당 해제하는 API의 문서이다.

0

정확히 이것은

이 절대로 retainCount가 아닌

을 호출해야하는 훌륭한 예입니다. 객체의 절대 보유 수는 구현 세부 사항이며 종종 의미가없는 값입니다.

무언가가 할당 해제 된 후에 메소드를 호출하는 동작은이 완전히 정의되지 않은 입니다. 이 경우 충돌이 발생할 수 있습니다. 좀비 감지 기능을 사용 설정하면 충돌이 발생합니다. retainCount 이제까지 0을 반환 할 수있는 방법이 전혀 없기 때문에

, 나는 컴파일러는 심지어 그것을 호출하는 경고를해야한다고 생각 0

+0

에 유지 수를 감소하는 객체 해제에 대한 이유가 없다. –

관련 문제