본문 바로가기

프로그래밍/아이폰 프로그래밍

26. View Controller 간의 변수 공유



View Controller 간의 변수 공유


하위 뷰에서 상위 뷰의 변수나 메소드를 호출하고 싶을때는 이렇게 사용하는 방법이 있습니다.




SecondViewController 에 Instance 변수로 FirstViewController *parent를 선언합니다.

상위 뷰에서 호출할 때

SecondViewController *second = [[SecondViewController alloc] init]; // 하위 뷰 객체 생성 후
second.parent = self; // 하위 뷰와 자신을 포인터 연결 합니다.
[self.navigationController pushViewController:second animated:NO];


이렇게 하면 하위 뷰에서 

parent.method...
parent.variable... 을 호출 할 수 있습니다.