0
我已經構建了一個簡單的記憶遊戲,用戶可以點擊一張卡片,直到所有卡片都配對爲止。然而,我的問題是,當用戶點擊兩張牌時,遊戲在2秒後崩潰「解開時意外發現無」。簡單記憶遊戲:發現無錯誤
我已經仔細檢查了所有圖像,並確保它們正確連接,但仍然出現錯誤。我的代碼如下:
@IBOutlet weak var frontImageView: UIImageView!
@IBOutlet weak var backImageView: UIImageView!
var card: Card?{
didSet {
guard let card = card else {return}
frontImageView.image = card.image
}
}
fileprivate(set) var shown: Bool = false
//Mark:- Card function properties
func showCard(_ show: Bool, animated: Bool){
frontImageView.isHidden = false
backImageView.isHidden = false //This is where i get the error.
shown = show
if animated {
if show{
UIView.transition(from: backImageView, to: frontImageView, duration: 0.3, options: .transitionFlipFromBottom, completion: { (finished: Bool) in
})
} else {
UIView.transition(from: frontImageView, to: backImageView, duration: 0.3, options: .transitionFlipFromBottom, completion: { (finished: Bool) in
})
}
} else {
if show{
bringSubview(toFront: frontImageView)
backImageView.isHidden = true
} else {
bringSubview(toFront: backImageView)
frontImageView.isHidden = true
}
}
哪一行崩潰? –
@DuncanC說什麼。設置一個斷點,找出哪條線路崩潰,並根據您的代碼,我敢打賭,如果沒有我們的幫助,您可以解決這個問題。 – dylanthelion