Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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

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 在代码中的containerview中嵌入viewcontroller?_Ios_Objective C_Swift_Storyboard - Fatal编程技术网

Ios 在代码中的containerview中嵌入viewcontroller?

Ios 在代码中的containerview中嵌入viewcontroller?,ios,objective-c,swift,storyboard,Ios,Objective C,Swift,Storyboard,我想在代码中将viewcontroller嵌入到containerview中 我在情节提要上放了一个containerview,我想在另一个情节提要上嵌入一个viewcontoller 我在下面试过了,但没用 你有什么建议吗 let storyboard: UIStoryboard = UIStoryboard(name: "AnotherStoryboard", bundle: nil) let vc:OtherViewController = storyboard.instantiateVi

我想在代码中将viewcontroller嵌入到containerview中

我在情节提要上放了一个containerview,我想在另一个情节提要上嵌入一个viewcontoller

我在下面试过了,但没用

你有什么建议吗

let storyboard: UIStoryboard = UIStoryboard(name: "AnotherStoryboard", bundle: nil)
let vc:OtherViewController = storyboard.instantiateViewControllerWithIdentifier("OtherViewController") as OtherViewController
self.addChildViewController(vc)
containerView.addSubview(vc.view)
vc.didMoveToParentViewController(self)

为了使代码正常工作,您必须做两个更改

  • containerview
    更改为
    self.view
  • 添加
    OtherViewController
    作为
    OtherViewController
    的情节提要ID
  • 这将使您的代码工作。

    什么是“不工作”?到底发生了什么?你都做了些什么?