我不知道这个错误是什么意思
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeaa26f48)
这意味着我不知道如何修复我的代码。请帮我。如果您需要,下面是我的代码。如果您需要更多代码,请问我。我希望你们能帮助我。编辑:我包含了我所有的代码。我希望你们可以使用它,很抱歉没有定义这个问题所必需的变量。我再次希望你们能解决这个问题。
var score = 0
var randomAmountOfTime = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime2 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime3 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime4 = Double(arc4random_uniform(5) + 2)
var randomAmountOfTime5 = Double(arc4random_uniform(5) + 2)
override func viewDidLoad() {
super.viewDidLoad()
if X != nil {
X.text = ""
}
if Puppy5 != nil {
Puppy5.isHidden = true
}
if Puppy4 != nil {
Puppy4.isHidden = true
}
if Puppy3 != nil {
Puppy3.isHidden = true
}
if Puppy2 != nil {
Puppy2.isHidden = true
}
if Puppy1 != nil {
Puppy1.isHidden = true
}
score = 0
if Score != nil {
Score.text = "Score - \(score)"
}
loadingProcess()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet var Score: UILabel!
@IBOutlet var X: UILabel!
@IBOutlet var Puppy5: UIButton!
@IBAction func puppy5(_ sender: Any) {
Puppy5.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy4: UIButton!
@IBAction func puppy4(_ sender: Any) {
Puppy4.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy3: UIButton!
@IBAction func puppy3(_ sender: Any) {
Puppy3.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy2: UIButton!
@IBAction func puppy2(_ sender: Any) {
Puppy2.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
@IBOutlet var Puppy1: UIButton!
@IBAction func puppy1(_ sender: Any) {
Puppy1.isHidden = true
score += 1
Score.text = "Score - \(score)"
}
func loadingProcess() {
if self.Puppy1 != nil && self.Puppy1.isHidden == true {
let when = DispatchTime.now() + randomAmountOfTime
DispatchQueue.main.asyncAfter(deadline: when) {
self.Puppy1.isHidden = false
self.loadingProcess()
}
} else if self.Puppy1 != nil && self.Puppy1.isHidden == false {
let when = DispatchTime.now() + 3
DispatchQueue.main.asyncAfter(deadline: when) {
self.Puppy1.isHidden = true
if self.X.text == "X" {
self.X.text = "X X"
} else if self.X.text == "" {
self.X.text = "X"
} else if self.X.text == "X X" {
self.X.text = "X X X"
}
}
}
self.loadingProcess()
}
最佳答案
您正在无条件地递归调用 self.loadingProcess()
。这个无限循环肯定会导致崩溃。
关于ios - 线程 1 : EXC_BAD_ACCESS (code=2, 地址=0x7ffeeaa26f48),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48936683/