2011-03-05 4 views
0

하위보기로 UINavigationController가있는 MyViewController가 있고 UINavigatioController에 스택에 대한 CustomView가 나타납니다. 내가하고 싶은 것은 CustomView에서 MyViewController의 메소드를 호출하는 것입니다. 그래서 이것을 시도했습니다 :부모보기 컨트롤러에서 함수/메서드를 호출하는 방법

UINavigationController *main = (UINavigationController*)[self parentViewController];  
MyViewController *parentContainer = (MyViewController*)[main parentViewController]; 
[parentContainer myParentMethod]; 

이 코드는 올바르지 않습니다.

+0

이 스레드가 발견되어 잘 작동합니다. http://stackoverflow.com/questions/3370666/call-method-in-nested-parent-controllers – Arcadian

답변

1

parentViewController 속성은 탐색 컨트롤러, 탭 표시 줄 컨트롤러 또는 모달 프레젠테이션 관계에서만 작동합니다. MyViewController 개체는 하위보기로 UINavigationController 개체의보기를 가지고 있지만 MyViewController가 UINavigationController 개체의 parentViewController임을 의미하지는 않습니다.

이 디자인을 유지해야하고 CustomView 개체에서 MyViewController 개체에 액세스해야하는 경우 가장 좋은 방법은 CustomView 개체에 MyViewController 개체 (예 : delegate 속성)에 대한 약한 참조를 허용하는 것입니다.

관련 문제