比较整数

时间:2016-10-03 14:44:36

标签: ios swift xcode integer

我的项目中有两个按钮,它将得分+ = 1添加到两个单独的标签中。我的目的是比较标签中的整数是否相等,并在另一个单独的标签中给出结果(在本例中为整数),这向我展示了方案。但按下两个按钮中的一个按钮没有任何反应。标签显示整数相等但不可能,因为标签中的整数不再相等。

mysql> SELECT * FROM t1
    ->   WHERE s1 IN (SELECT s2 FROM t2 ORDER BY s1 LIMIT 1);
ERROR 1235 (42000): This version of MySQL doesn't yet support
 'LIMIT & IN/ALL/ANY/SOME subquery'

}

1 个答案:

答案 0 :(得分:0)

只有在加载ViewController视图时才会调用

viewDidLoad。如果要在每次按下按钮时检查整数,必须明确地执行:

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

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

@IBAction func btn1(_ sender: AnyObject) {
    scoreAdd += 1
    score1.text = "\(scoreAdd)"

    self.setTimeText()
}

@IBAction func btn2(_ sender: AnyObject) {
    scoreAdd1 += 1
    score2.text = "\(scoreAdd1)"

    self.setTimeText()
}

/// Is called whenever a score changes
func setTimeText() {
    if scoreAdd == scoreAdd1 {
        time.text = "\(regulargame)"
    } else {
        overtime = regulargame + 30
        time.text = "\(overtime)"
    }
}