1

일부보기 컨트롤러가 있고 일부 단추를 클릭하면 UINavigationController로 래핑 된 modalView를 만들고 제시합니다.modalViewController는 콜백을 위임합니다 - HowTo?

DscViewController *enterDescription = [[[DscViewController alloc] init] autorelease]; 


    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:enterDescription]; 
    [self presentModalViewController:navController animated:YES]; 
    [navController release]; 

문제는, 내 (부모) 뷰 컨트롤러 대리인이 될 수 있도록, 내가 modalViewController에서 어떤 버튼을 클릭 할 때 (예를 들어 완료)하는 방법을 모달를 닫 부모님의 ViewController의 일부 메소드를 호출하는 것입니다 모달 입력에서 약간의 절약을합니까?

답변

1

하나의 컨트롤러가 상위 컨트롤러로 하여금 핸드 헬드해야 할 작업을 수행하도록하는 것이 좋은 습관이라고 생각하지 않습니다. 당신은 당신 만 parentViewController에 저장을 처리 어떤 이유로 당신이 당신의 done 버튼 액션을 가리킬 수 있습니다 경우 항상 현재의 ViewController의 방법에 관한 것이다. 당신이 현재 모달를 닫

self.parentViewController을 사용하고 트리거 self.parentViewController을 사용할 수 있습니다 부모의 보존 메소드.

또는 당신의 버튼을 직접에 self.parentViewController

[button addTarget:self.parentViewController action:@selector(someMethodInParentViewController) forControlEvents:UIControlEventTouchUpInside]; 
+0

내가 가진이 "인식 할 수없는 선택기 인스턴스에 전송 ..."이것에 오류가 예를 보여 위임 설정합니다. 물론, 내 부모보기 컨트롤러에서 - (void) someMethodInPrentView – dormitkon

+0

내 modalViewController NavigationController 함께 래핑되어 있기 때문에입니다. – dormitkon

+0

당신은 당신의 루트 viewController UINavigationViewController 포함 된 모달 viewController 참조에 의해 항상 전달할 수 있습니다. 델리게이트를 사용하지 않고도 NSNotifications를 사용할 수 있습니다. – Cyprian