gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:55:17 24 4
gpt4 key购买 nike

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

最佳答案

听起来您需要的是容器 View 。这些 View 可以容纳较小的 View ,并使用独立的 ViewController 逻辑运行。就像您 View 中的单独 View 一样。这里有一个关于使用 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)

关于swift - 使用 Swift/Xcode 访问菜单栏项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33705109/

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