【发布时间】:2016-06-23 17:18:31
【问题描述】:
我想通过单击按钮使标签消失并重新出现,然后再次单击按钮重新出现,以减少屏幕上的混乱。
以下代码在首次运行时使按钮消失。我希望它这样做,但是当我关闭它然后再次运行它并按下按钮时,代码突然不起作用,这意味着我的标签没有消失。我没有更改任何代码;我所做的只是再次运行它。
我这样做是作为学校小组项目的一部分。如果有人可以帮助我解决我的问题,那就太好了。谢谢。
附: PrepInfo 是我要隐藏的按钮,PrepButtton 是按下时我想让PrepInfo 标签消失的按钮。
import UIKit
class BackgroundViewController: UIViewController {
@IBAction func PrepButton(sender: AnyObject) {
func hide() {
PrepInfo.hidden = false
}
hide()
}
@IBOutlet weak var PrepInfo: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
【问题讨论】:
-
hide() 函数似乎隐藏了 false 这意味着它没有被隐藏。在 PrepButton 中也有 hide 函数,这有点奇怪的代码结构。只需将 PrepInfo.hidden = !PrepInfo.hidden 放入 PrepButton。
标签: swift