ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • UINavigationController 사용시 self.navigationController
    프로그래밍/아이폰 프로그래밍 2011. 5. 30. 11:00

    UINavigationController 를 사용한 계층구조의 App 제작시 다음과 같이 하위 계층의 UIViewController 진입시
    pushViewController 를 사용하게되는데요,

    SecondDepthViewController *sdViewController = [[SecondDepthViewController alloc] 
    initWithNibName:@"SecondDepthViewController" bundle:nil];
    [self.navigationController pushViewController:sdViewController animated:YES];
    [sdViewController release];

    이를 사용하다보니 위의 self.navigationController 에서 navigationController 는 어디서 나온건지 궁금했습니다.
    (보통 navigationController는 최초에 AppDelegate에 담아서 시작했는데 어떻게 하위 UIViewController 에서 접근이 가능한건지?)

    찾아보니 UIViewController 클래스에 navigationController 프로퍼티가 있더군요

    navigationController
    A parent or ancestor that is a navigation controller. (read-only)

    @property(nonatomic, readonly, retain) UINavigationController *navigationController
    Discussion
    Only returns a navigation controller if the view controller is in itsstack. This property is nil if a navigation controller cannot be found.

    즉 UINavigationController 에 담긴(push/스택된) View controller 들이라면 self.navigationController 로 접근이 가능하도록
    되어 있기에 위처럼 사용이 가능하다고 합니다.

    저처럼 UINavigationController 처음 사용 시작하시는분들께 도움이 되면 좋겠습니다. 

    [출처 - http://cafe.naver.com/mcbugi.cafe]

    댓글