iOS 8 Swift:点击按钮时无法取消隐藏/隐藏UIView

时间:2015-02-14 14:27:30

标签: xcode swift ios8

这让我发疯了。我试图在按钮单击时取消隐藏隐藏的UIView,但它无法正常工作。这是代码

import UIKit
class DownloadViewController: UIViewController {

    @IBOutlet var activityView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.activityView.hidden = true
    }

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

    @IBAction func downloadAction(sender: AnyObject) {
        self.activityView.hidden = false
    }    
}

请帮帮我。这让我疯了,它没有做这么简单的事情。

3 个答案:

答案 0 :(得分:1)

确保您的插座连接到Interface Builder中的正确按钮,尝试通过从IB中的按钮拖动到@IBOutlet代码再次连接它。

答案 1 :(得分:1)

此代码有效,您是否收到错误或按钮没有执行任何操作?

答案 2 :(得分:0)

Swift 3

导入UIKit class DownloadViewController:UIViewController {

@IBOutlet var activityView: UIView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    self.activityView.isHidden = true
}

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

@IBAction func downloadAction(sender: AnyObject) {
    self.activityView.isHidden = false
}    

}