使用Swift / Xcode访问菜单栏项目

时间:2015-11-14 04:28:16

标签: swift macos sockets

我是swift的新手,我想使用swiftSocket Library创建一个简单的聊天应用程序。我想要一个可以在客户端模式或服务器模式之间切换的OSX应用程序。我创建了两个菜单项“客户端”和“服务器”。启动应用程序时,根据选择的菜单项,将进行相应的客户端或服务器调用。但是,我不确定如何在视图控制器中访问这些菜单项的IBAction方法。我怎么处理这个?

1 个答案:

答案 0 :(得分:0)

您需要的是容器视图。这些视图可容纳较小的视图,使用独立的ViewController逻辑运行。就像您视图中的单独视图一样。这里有一个关于使用Container Views here,

的好教程

这里有一些关于如何以编程方式使用View Controller设置容器的示例代码,但它只是一个演示!

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        self.controller = storyboard.instantiateViewControllerWithIdentifier(storyboardID) 
        controller.view.frame = CGRectMake(0, 0, theWidth, theHeight)
        self.view.addSubview(controller.view)
        self.addChildViewController(controller)
        controller.didMoveToParentViewController(self)