Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ParentViewController如何显示ChildViewController?_Ios_Objective C - Fatal编程技术网

Ios ParentViewController如何显示ChildViewController?

Ios ParentViewController如何显示ChildViewController?,ios,objective-c,Ios,Objective C,我已经创建了一个ChildViewController数组,但是如何使ParentViewController显示其中一个ChildViewController(arrayChildViewController[0]) 在ParentViewController中: [self addChildViewController:arrayChildViewController[0]]; [arrayChildViewController[0] didMoveToParentViewControlle

我已经创建了一个
ChildViewController
数组,但是如何使
ParentViewController
显示其中一个
ChildViewController(arrayChildViewController[0])

在ParentViewController中:

[self addChildViewController:arrayChildViewController[0]]; [arrayChildViewController[0] didMoveToParentViewController:self];

[self addChildViewController:arrayChildViewController[1]]; [arrayChildViewController[1] didMoveToParentViewController:self];

[self addChildViewController:arrayChildViewController[2]]; [arrayChildViewController[2] didMoveToParentViewController:self];
在arrayChildViewController[1]中:(arrayChildViewController是一个导航控制器,我添加了一个UIImagePickerController,下面是它的委托方法)


parentViewController无法显示arrayChildViewController[1],它将成为arrayChildViewController[0]。希望我能说清楚。

您需要像这样添加它并将其移动到父视图控制器

[self addChildViewController:arrayChildViewController[0]];
[arrayChildViewController[0] didMoveToParentViewController:self];

尝试下面的代码。。它将帮助您。

代码:

[self.parentViewController addChildViewController:childViewControllers[0]];
[self.parentViewController addChildViewController:childViewControllers[1]];
[self.parentViewController.childViewControllers objectAtIndex:1];

ParentViewController
中编写以下代码:

[self addChildViewController:arrayChildViewController[0]];
[arrayChildViewController[0] didMoveToParentViewController:self];

[self addChildViewController:arrayChildViewController[1]];
[arrayChildViewController[1] didMoveToParentViewController:self];

[self addChildViewController:arrayChildViewController[2]];
[arrayChildViewController[2] didMoveToParentViewController:self];
这是arrayChildViewController[1]:

 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { //         [picker dismissViewControllerAnimated:YES completion:nil];   [self.parentViewController dismissViewControllerAnimated:YES completion:nil];  [self.parentViewController.childViewControllers objectAtIndex:1];
 }

parentVieController
无法显示
arrayChildViewController[1]
,它变成了
arrayChildViewController[0]

您在使用导航控制器吗?@laura wen我已经发布了答案,请尝试一下。@laura wen请重播。好的,等等。非常感谢。@laura wen请分享你的代码……我已经这么做了。对不起,我没说清楚。我向parentViewController添加了三个ChildViewController,但是如何显示arrayChildViewController[0]?谢谢。@stefan salacity您代码的最后一行给出了错误。可能是因为我是从头开始写的。谢谢你的提醒。这会给你带来错误。。。“在类型id上找不到属性视图”@laura wen删除此行[self.parentViewController.childViewControllers objectAtIndex:1];而不是写这一行[self.childViewControllers objectAtIndex:1]@laura wen分享你的代码,以便我能看到它并尝试帮助你。嗨。。朋友,如果我的答案有任何错误,请通知我,而不是否决投票,这样下次我就不会犯同样的错误了。我已经在我的设备上运行了这个答案后发布了。朋友们,这是正确的代码你为什么投反对票。。在否决投票之前,请先运行并检查它。这段代码运行得很好。=.=事实上,不是我,我甚至不能投反对票和赞成票:-(,因为我的声誉不到15岁。你知道,昨晚很晚了,所以我回家了。我已经试过了,确实有效,非常感谢。@laura wen谢谢你。
 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { //         [picker dismissViewControllerAnimated:YES completion:nil];   [self.parentViewController dismissViewControllerAnimated:YES completion:nil];  [self.parentViewController.childViewControllers objectAtIndex:1];
 }