두 개의 숫자를 비교 중이며 두 개의 숫자가 같지 않으면 카운터가 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