2016-06-24 9 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'性を有している希望

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

このようにあなたがそれを作ることができます – Shubhank

答えて

関連する問題