1
我有看法。 當我點擊btnStartWork時,我想將按鈕設置爲隱藏(工作),標籤startTime顯示開始時間(工作)和btnEndWork顯示(工作)。 當我點擊btnEndWork時,我沒有隱藏任何按鈕,並且btnEndWork仍在顯示。他還設置endTime標籤的結束時間,但也更新startTime。這是真的有線。快捷按鈕隱藏/顯示不工作
class FirstViewController: UIViewController {
@IBOutlet weak var startTime: UILabel!
@IBOutlet weak var endTime: UILabel!
@IBOutlet weak var btnStartWorkLabel: UIButton!
@IBOutlet weak var btnEndWorkLabel: UIButton!
@IBAction func btnStartWork(_ sender: Any) {
let currentdate = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
let convertedDate = dateFormatter.string(from: currentdate)
startTime.text = "\(convertedDate)"
btnStartWorkLabel.isHidden = true
btnEndWorkLabel.isHidden = false
}
@IBAction func btnEndWork(_ sender: Any) {
let currentdate = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
let convertedDate = dateFormatter.string(from: currentdate)
endTime.text = "\(convertedDate)"
btnStartWorkLabel.isHidden = false
btnEndWorkLabel.isHidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
更新問題
我怎麼能保存次,兩次,當點擊btnEndWork何時工作?
刪除按鈕,然後再次創建它。 – beli3ver
我複製粘貼很多,所以一直運行到這一點,也請注意,如果您從另一個控制器複製粘貼,它將保持與前一個控制器的連接。 –