gpt4 book ai didi

ios - iOS Check ViewController是否具有ChildViewController?

转载 作者:行者123 更新时间:2023-12-01 18:44:07 26 4
gpt4 key购买 nike

当viewController有任何ChildViewController时,我想做些事情。

我正在使用下面的代码添加子viewController:

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?

最佳答案

你可以这样

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

希望这个帮助

关于ios - iOS Check ViewController是否具有ChildViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38011072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com