2016-06-24 2 views
1

viewController에 ChildViewController가있을 때 뭔가하고 싶습니다. 이제iOS Check ViewController에 ChildViewController가 있는지 확인 하시겠습니까?

ParentVC *parentVC = [self.storyboard instantiateViewControllerWithIdentifier:@"IDParentVC"]; 

ChildVC *childVC = [self.storyboard instantiateViewControllerWithIdentifier:@"IDChildVC"]; 

[childVC.view setFrame:CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)]; 
[parentVC addChildViewController:childVC]; 
[parentVC.view addSubview:childVC.view]; 
[childVC didMoveToParentViewController:parentVC]; 

어떻게 ParentVC이 ChildVC가있는 경우 확인 :

나는 아이의 ViewController를 추가하는 코드 아래 사용하고 있습니다?

+1

'UIViewController' 클래스를 사용하면 열거 할 수있는'childViewControllers' 속성이이 도움이 그것을 만들 수 있습니다 – Shubhank

답변

3

for (UIViewController *child in parentVC.childViewControllers) { 
    if ([child isKindOfClass:[childVC class]) { 
     //your ChildVC here 
    } 
} 

희망처럼

관련 문제