, 내가 관찰하고있어 프레임 변경 :이 observeValueForKeyPath : ofObject의 문제점 : 변경 : 컨텍스트 : 구현? 내있는 UIScrollView 서브 클래스에서
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self && [keyPath isEqualToString:@"frame"]) {
[self adjustSizeAndScale];
}
if ([UIScrollView instancesRespondToSelector:@selector(observeValueForKeyPath:ofObject:change:context:)]) {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; // Exception
}
}
하지만이 코드로 예외를 얻을 :
[self addObserver:self forKeyPath:@"frame" options:0 context:NULL];
내 observeValueForKeyPath:ofObject:change:context:
구현은 다음과 같다
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<WLImageScrollView: 0x733a440; baseClass = UIScrollView; frame = (0 0; 320 416); clipsToBounds = YES; layer = <CALayer: 0x7346500>; contentOffset: {0, 0}>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: frame
Observed object: <WLImageScrollView: 0x733a440; baseClass = UIScrollView; frame = (0 0; 320 416); clipsToBounds = YES; layer = <CALayer: 0x7346500>; contentOffset: {0, 0}>
Change: {
kind = 1;
}
Context: 0x0'
그것은 UIScrollView가 observeValueForKeyPath:ofObject:change:context:
을 구현하지만 위의 예외를 throw한다는 것을 의미합니까?
그렇다면 observeValueForKeyPath:ofObject:change:context:
을 올바르게 구현하여 관심있는 변경 사항을 처리하고 관심있는 변경 사항을 처리 할 수있는 방법을 제공하려면 어떻게해야합니까?
다른 일에 대해 이야기에 링크 된 기사 : : ofObject : 변경 : 슈퍼 클래스가 observeValueForKeyPath 구현하지 않는이 같이
컨텍스트를 :. 하지만 코드에서 볼 수 있듯이 UIScrollView는이를 구현합니다. 그렇지 않으면 super 메서드가 호출되지 않습니다. – an0
메소드를 구현하더라도 관찰되지 않는 키를 검출하여 예외를 throw하는 코드가있을 수 있습니다. 따라서 'NSInternalInconsistency' 예외는 "수신되었지만 처리되지 않았습니다", 이는 인스턴스로 전송 된 인식 할 수없는 선택자 인 NSInvalidArgumentException과 다릅니다 ". –
그게 내가 묻고있는거야. 그래서 observeValueForKeyPath : ofObject : change : context :의 기본 구현은 NSObject에서 예외를 던집니까?그렇다면 수퍼 클래스가 주요 가치 변화를 통보 받기를 원하는지 여부를 감지하기 위해 할 수있는 방법이 없습니다. – an0