xcode iOS 8 Swift:无法在单击按钮时取消隐藏/隐藏 UIView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28516576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 8 Swift: Cannot unhide/hide UIView on button click
提问by Nick
This is driving me crazy. I am trying to un-hide a hidden UIView on button click but its not working. Here is the code
这真让我抓狂。我试图在单击按钮时取消隐藏隐藏的 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
}
}
Please help me. This is driving me nuts, that its not doing such a simple thing.
请帮我。这让我发疯,它没有做这么简单的事情。
采纳答案by Leonardo
Make sure that your outlet is connected to the correct button in Interface Builder, try connecting it again by ctrl-dragging from the button in IB to the @IBOutlet code.
确保您的插座连接到 Interface Builder 中的正确按钮,尝试通过 ctrl 从 IB 中的按钮拖动到@IBOutlet 代码来再次连接它。
回答by Dan Oswalt
This code works, are you getting an error or does the button not do anything?
此代码有效,您是否收到错误或按钮没有执行任何操作?
回答by Faris
Swift 3
斯威夫特 3
import UIKit class DownloadViewController: UIViewController {
导入 UIKit 类 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
}
}
}