gpt4 book ai didi

ios - 导航按钮不显示

转载 作者:可可西里 更新时间:2023-11-01 02:19:25 26 4
gpt4 key购买 nike

我正在尝试在 iOS 工具栏中显示一个按钮,理论上它非常简单并且应该可以工作:

import UIKit

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let refresh = UIBarButtonItem(barButtonSystemItem: .Refresh, target: self, action: "refreshTapped")
navigationItem.leftBarButtonItem = refresh
navigationController?.toolbarHidden = false
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

还是不行。按钮不显示。我尝试重新启动模拟器,从头开始创建项目等。所以我想这是我的 Swift 初学者解决问题的方式的缺陷,但我根本看不到它。

最佳答案

转到您的 Storyboar,选择 View Controller,然后在 Xcode 顶部栏中选择 Editor -> Embed in -> Navigation Controller。

在你的代码中,当你说

navigationController?.toolbarHidden = false

如果你 CMD + 点击 navigationController?您会在变量旁边看到一条评论:“如果此 View Controller 已被推送到导航 Controller 上,请返回它。”

因此仅当您的 View 已被推送到导航 Controller 时才有效。

关于ios - 导航按钮不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024041/

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