我比較兩個數字,如果兩個數字不相等,則計數器增加1。 但是,標籤不會更新,並且開始按鈕變灰。該按鈕變灰,直到這兩個數字相等。快速按鈕變灰
import UIKit
enum modes {
case start
case cancel
}
class ViewController: UIViewController {
var mode: modes = modes.start
var num1: Int = 0
var num2: Int = 1
var count: Int = 0
@IBOutlet weak var start: UIBarButtonItem!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var countLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// 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 startClicked(sender: AnyObject) {
if (mode == modes.start) {
mode = modes.cancel
start.title = "cancel"
checkNums()
} else if (mode == modes.cancel) {
mode = modes.start
start.title = "start"
num1 = 0
num2 = 1
}
}
func checkNums() {
while (num1 != num2) {
let temp: UInt32 = 100000
num1 = Int(arc4random_uniform(temp))
num2 = Int(arc4random_uniform(temp))
print("\(num1) and \(num2)")
update()
}
func update() {
count += 1
label.text = "\(num1) and \(num2)"
countLabel.text = "\(count)"
}
}
請幫忙! 謝謝。
的使用UICountingLabel你試過啓動按鈕的屬性?例如:myButton.enabled = false將會禁用它。 – Array
@Array是的,但問題是程序沒有更新,它比較了兩個值。它只更新最後的結果。 – Asada