【发布时间】:2021-07-10 14:48:49
【问题描述】:
想要在我的标签栏旁边浮动一个按钮。按下时,此按钮将打开一个可以导航的视图(因此视图控制器嵌入在导航控制器中(?))。
在 UITabBarController {
ViewDidLoad() {
super.viewDidLoad()
//I have my 5 tab bar items set up programatically here.
//The middle tab bar item is disabled because the button is on top of it
setupMiddleButton()
}
我的 setupMiddleButton 函数
let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 52, height: 52))
//..various styling and alignment values...
view.addSubview(menuButton)
menuButton.addTarget(self, action: #selector(menuButtonAction(sender:)), for: .touchUpInside)
最后我尝试添加代码来推送视图控制器,但是点击按钮时我收到 nil。
@objc private func menuButtonAction(sender: UIButton) {
let createController = CreateViewController()
let nav3 = UINavigationController(rootViewController: createController)
nav3.navigationController!.pushViewController(createController, animated: true)
【问题讨论】:
-
“我在点击按钮时收到 nil”是什么意思?
标签: ios swift uinavigationcontroller uibutton uitabbarcontroller