2010-02-24 6 views
4

나는 모달 뷰를 표시하려면이 코드를 발견아이 패드

- (void)add:(id)sender { 
    // Create the root view controller for the navigation controller 
    // The new view controller configures a Cancel and Done button for the 
    // navigation bar. 
    RecipeAddViewController *addController = [[RecipeAddViewController alloc] 
         initWithNibName:@"RecipeAddView" bundle:nil]; 
    addController.delegate = self; 

    // Create the navigation controller and present it modally. 
    UINavigationController *navigationController = [[UINavigationController alloc] 
          initWithRootViewController:addController]; 
    [self presentModalViewController:navigationController animated:YES]; 


    // The navigation controller is now owned by the current view controller 
    // and the root view controller is owned by the navigation controller, 
    // so both objects should be released to prevent over-retention. 
    [navigationController release]; 
    [addController release]; 
} 

내 질문이 코드를 (내가 buttonPress 방법에 배치거야)

구현합니까 어떻게

헤더 파일에 아무 것도 정의해야합니까? 나를 혼란스럽게하는 비트는 apple on이 헤더 파일을 제공하지 않기 때문에 아무 것도 없어야하는지 알 수 없습니까?

이 코드는 RecipieAddViewController를 참조합니다. "UIViewController"로 무엇을 표현합니까?

헤더 파일에 위임자로 무엇을 넣을 까? 다른 곳에서는 이걸 설정해야합니까? 재산 같은 거요?

다른 방법이 있습니까?이 코드를 내 buttonPress 메서드에 복사하여 작동 시키려면 어떻게해야합니까?

모든 질문에 대해 죄송합니다.

답변

4

내 질문에 내가

가 버튼의 touch up inside을 결합 -(IBAction)add:(id)sender 같은 IBAction 같은 방법을 정의하고 인터페이스 빌더 (나는 buttonPress 방법에 배치거야)이 코드를 구현합니까 어떻게 이벤트를보기 컨트롤러 객체의 add: 작업 콘센트에 전달합니다.

헤더 파일에 아무 것도 정의해야합니까? 나를 혼란스럽게하는 비트는 apple on이 헤더 파일을 제공하지 않기 때문에 아무 것도 없어야하는지 알 수 없습니까?

아니요. 이 모든 것들이 필요합니다. UIKit.h 일반적으로 메소드를 추가하거나 인스턴스 변수를 추가하거나 사용자 정의 클래스를 포함하려면 헤더를 변경해야합니다. 그러나 해당 클래스를 사용하려면 어딘가에 (헤더 또는 구현 파일에) #import RecipeAddViewController.h이 필요할 수 있습니다. 이는 다른 파일에서 사용하고자하는 사용자 지정 클래스에 적용됩니다.

코드는 RecipieAddViewController를 참조합니다. "UIViewController"로 무엇을 표현합니까?

밀어 넣으려는 뷰 컨트롤러 클래스로 바꿉니다. UIViewController 자체가 드물게 알몸으로 유용합니다. 그것은 하위 클래스로 만들어졌습니다. 따라서 UIViewController에서 상속받은 새 클래스를 만들고 헤더를 가져 와서 만들고 인스턴스를 만들고 내비게이션 컨트롤러에 푸시합니다.

+0

대단히 감사합니다. 귀하의 답변은 훌륭했고 많이 정리되었습니다. :) – Dave