Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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 通过实现代码在情节提要中显示多个UIViewController_Ios_Swift_Xcode - Fatal编程技术网

Ios 通过实现代码在情节提要中显示多个UIViewController

Ios 通过实现代码在情节提要中显示多个UIViewController,ios,swift,xcode,Ios,Swift,Xcode,更具体地说, 假设我有一个UIViewControllera,当我在a中按下由代码创建的按钮时,我想显示另一个UIViewControllerB,其中B是在故事板中设计的。可以通过编码完成,但不使用情节提要中视图控制器之间的连接。谢谢。当然 确保已将情节提要标识符添加到ViewController B 最后,在ViewController A中: let YourStoryBoard = UIStoryboard(name: "YourStoryBoard", bundle: nil) let

更具体地说,

假设我有一个
UIViewController
a,当我在a中按下由代码创建的
按钮时,我想显示另一个
UIViewController
B,其中B是在
故事板中设计的。可以通过编码完成,但不使用
情节提要中
视图控制器之间的连接。谢谢。

当然

确保已将情节提要标识符添加到ViewController B

最后,在ViewController A中:

let YourStoryBoard = UIStoryboard(name: "YourStoryBoard", bundle: nil)
let vc = YourStoryBoard.instantiateViewController(withIdentifier: "VCB_StoryBoard_Identifier") as! ViewControllerB
如果ViewController中嵌入了UINavigationController

self.navigationController?.pushViewController(vc, animated: true)
否则从ViewController A显示ViewController B

self.present(vc, animated: true, completion: nil)
编辑:

设置故事板标识符,如下图所示

通过设置ViewController的类,将ViewControllerB类与故事板VC关联。如下图所示


您必须创建一个新的cocoa touch类->UIViewController->“ViewControllerb”

将情节提要中的名称添加到视图中,然后执行以下操作:

let storyboard=UIStoryboard(名称:“YourStoryBoard”,bundle:nil)

将vc=storyboard.InstanceEviewController(标识符为:“VCB\U storyboard\U标识符”)设置为!ViewContollerB

尝试以下操作:

点击
UIViewController
A
中的按钮

func onTapButton()
{
    let controller = UIStoryboard.init(name: "YOUR_STORYBOARD_NAME", bundle: nil).instantiateViewController(withIdentifier: "ViewControllerBIdentifier") as! ViewControllerB
    self.present(controller, animated: true, completion: nil)
}
这里,

ViewControllerBIdentifier
StoryboardID
对应于
UIViewController
B


ViewControllerB
class
对应于
UIViewController
B

对不起,我如何声明“ViewControllerB”我在脚本视图的Identity:storyboard ID中键入名称,然后我尝试在下面的代码中键入相同的名称,让vc=YourStoryBoard.InstanceEviewController(带有标识符:“VCB\u StoryBoard\u标识符”)作为!但它显示未声明在我成功执行此操作后,它表示新视图不在窗口层次结构中。如何解决itAttempt以显示不在窗口层次结构中的视图!如何解决这个问题?谢谢