如何隐藏按钮和禁用按钮

时间:2017-11-24 23:46:10

标签: ios swift

我正在尝试为员工创建小型餐厅应用。如果用户点击该按钮,我希望单击按钮被禁用,并且我想要显示文本字段和另一个确定按钮,我将表号作为按钮。如果我点击禁用按钮我想要启用它。

import UIKit

 class ViewController: UIViewController {

var total = 0
@IBOutlet weak var okButton: UIButton!
@IBOutlet weak var userInput: UILabel!
@IBOutlet weak var userValue: UITextField!



  @IBAction func okButton(_ sender: UIButton) {



    if userValue.text != nil{
    userInput.text = String(0)
    let userValueint: Int? = Int(userValue.text!)
    total = total + userValueint!
    let convertText = String(total)
    userInput.text = convertText
    userValue.text = String(0)

    userValue.isHidden = true

    okButton!.isHidden = true

   }
    else{
        print("Please Inter values")
    }



   }


  @IBAction func buttenPressed(_ sender: UIButton)
    {
        userValue.isHidden = false
        okButton.isEnabled = true





}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    userValue.isHidden = true

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    okButton.isHidden = false
}

}

到目前为止,我可以在开头隐藏textField,并且可以在单击表格按钮时启用,但我无法隐藏确定按钮并禁用表格按钮。有什么建议吗?

2 个答案:

答案 0 :(得分:0)

首先,您无法点击已禁用的按钮。其次,使用Rails.logger代替viewDidLoad

答案 1 :(得分:0)

我猜您的表格按钮为sender,因此禁用发件人并显示“确定”按钮

@IBAction func buttenPressed(_ sender: UIButton) {
        sender.isEnabled = false
        userValue.isHidden = false
        okButton.isHidden = false
        okButton.isEnabled = true
       }