隐藏/显示按钮,用于检查ios中的结果

时间:2018-01-29 04:51:33

标签: ios swift

我试图运行以下代码,我认为这是直接向前但我一直在; layer =>

故事板有3个文本字段和两个按钮,我得到的消息是答案是正确的(If语句的第二部分。 谢谢,

import UIKit

class ViewController: UIViewController {

// Create outlet for both the button
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!



@IBOutlet weak var txt1: UITextField!

@IBOutlet weak var image: UIImageView!
@IBOutlet weak var result: UITextField!
@IBOutlet weak var txt2: UITextField!
override func viewDidLoad() {

    super.viewDidLoad()
    //hidden button on start
   button2.isHidden = true

}



//Here is the actionbutton1 which is visible
@IBAction func button1(sender: AnyObject) {
    //Make button2 Visible
    let firstValue : Int? = Int(txt1.text!)
    let secondValue : Int? = Int(txt2.text!)

    let convert = firstValue! + secondValue!
   let converText = String(convert)


    //result.text = converText
    if result.text != converText {
    print ("wrong")
    button2.isHidden = true

    }
        else{
        print(result)// result right

    //show the button
  button2.isHidden = false


    }

}

}

0 个答案:

没有答案