2011-08-17 6 views
0

다음 내 물건 ....입니다KVO의 아이폰 .. 그는 viewWillAppear 메소드에서 observeValueForKeyPath 메소드를 호출하는 방법은 무엇입니까?

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    if ([object isKindOfClass:[UIAccelerometer class]]) { 
    NSNumber *interfaceValue = [change objectForKey:NSKeyValueChangeNewKey]; 
    UIInterfaceOrientation toInterfaceOrientation = [interfaceValueintValue];   
    //here is my code.... 
    } 
+0

무엇이 당신 질문입니까? – jtbandes

답변

1

내가 제대로 이해하면, 당신은 키 값이 변경 될 때 특정 코드를 실행하고자하는 - 그리고 당신은 또한 viewWillAppear에서이 코드를 실행하고 싶습니다. 오히려 프로그래밍 KVO 방법을 트리거하는 것보다, 단순히 두 위치에서 호출 할 수있는 별도의 함수를 만들 : 나는 완전히 마크를 놓친 경우

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    [self myKeyValueObservationMethod]; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    [self myKeyValueObservationMethod]; 
} 

- (void)myKeyValueObservationMethod { 
    // here is my code.... 
} 

를, 다음 질문을 편집하고 설명에 자세한 내용을 추가하십시오 문제의

+0

예. 같은 코드를 viewWillAppear()에 두어 동일한 작업을 수행했습니다 ... –

관련 문제