我是 Xcode 的初学者,我正在尝试将 YouTube 视频嵌入到侧边菜单的子控制器中,但我无法在故事板上连接我的视图控制器文件和我的 UI 视图控制器。 我正在编写一个侧面菜单控制器,子视图控制器使用以下方式调用:
class Course2ViewController: UIViewController, MenuControllerDelegate2 {
private var sideMenu: SideMenuNavigationController?
private let abaController = abaViewController()
private let abbController = abbViewController()
private let abcController = abcViewController()
private let abdController = abdViewController()
override func viewDidLoad() {
super.viewDidLoad()
let menu = MenuController2(with: SideMenuItem2.allCases)
menu.delegate = self
sideMenu = SideMenuNavigationController(rootViewController: menu)
sideMenu?.leftSide = true
SideMenuManager.default.leftMenuNavigationController = sideMenu
SideMenuManager.default.addPanGestureToPresent(toView: view)
AddChildControllers()
}
private func AddChildControllers() {
addChild(abaController)
addChild(abbController)
addChild(abcController)
addChild(abdController)
view.addSubview(abaController.view)
view.addSubview(abbController.view)
view.addSubview(abcController.view)
view.addSubview(abdController.view)
abaController.view.frame = view.bounds
abbController.view.frame = view.bounds
abcController.view.frame = view.bounds
abdController.view.frame = view.bounds
abaController.didMove(toParent: self)
abbController.didMove(toParent: self)
abcController.didMove(toParent: self)
abdController.didMove(toParent: self)
abaController.view.isHidden = true
abbController.view.isHidden = true
abcController.view.isHidden = true
abdController.view.isHidden = true
}
@IBAction func didTapMenuButton2() {
present(sideMenu!, animated: true)
}
func didSelectMenuItem2(named: SideMenuItem2) {
sideMenu?.dismiss(animated: true, completion: nil)
title = named.rawValue
switch named {
case.aba:
abaController.view.isHidden = false
abbController.view.isHidden = true
abcController.view.isHidden = true
abdController.view.isHidden = true
case.abb:
abaController.view.isHidden = true
abbController.view.isHidden = false
abcController.view.isHidden = true
abdController.view.isHidden = true
case.abc:
abaController.view.isHidden = true
abbController.view.isHidden = true
abcController.view.isHidden = false
abdController.view.isHidden = true
case.abd:
abaController.view.isHidden = true
abbController.view.isHidden = true
abcController.view.isHidden = true
abdController.view.isHidden = false
}
}
}
然后,我尝试通过给后面的类“abaViewController”将我的 abaViewController 文件连接到故事板上的新视图控制器,但是我在故事板上的视图控制器没有显示。任何提示/解决方案?
嗨Airone
下面介绍如何直接从 Swift UI 创建 Story Board
如果您发现 SwiftUI 有点太复杂而无法开始(大多数人这样做),我真的建议在您的下一个项目中选择“Storyboard”或“UIKit”。它允许您轻松添加视图控制器并快速允许按钮移动到其他视图控制器只需按住按钮,然后是“控制”,然后是新屏幕。 UIKit 还允许您管理设计的各个方面y(也管理格式和约束)无需一行代码。更好的是,您可以将 SwiftUI 和 UIKit 结合在一起.
谢谢,我希望下面的代码对您有所帮助:
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController
// Alternative way to present the new view controller
self.navigationController?.showViewController(vc, sender: nil)