昨天空畫面為今天一次都沒有配對到的話,會出現一個讓你再配對一次的Label
今天會是做tap 這個Label然後跳出一個View來讓你打上你說對他說的話
因為沒有特別再去碰AI,所以這次的判斷會是讓他再跑一次random去配對
如果再沒有,可以去拜拜求個平安
let ran = Int.random(in: 0...9)
if ran == 1 || ran == 5 || ran == 9 {
let index = ran / 2
emptyView.isHidden = true
matchView.configure(imageURL: data[index])
matchView.isHidden = false
}
@IBOutlet weak var tapButton: UILabel! {
didSet {
tapButton.isUserInteractionEnabled = true
}
}
@objc func tapOneMoreButton() {
delegate?.tapOneMoreChance()
}
weak var delegate: EmptyViewDelegate?
創立Protocol以傳遞Delegate
記得要繼承AnyObject
protocol EmptyViewDelegate: AnyObject {
func tapOneMoreChance()
}
創立RetryViewController
建立一個TextView、Button,Button送出按鈕後,就通知到SlideViewController進行上面的邏輯運算
protocol RetryViewControllerDelegate: AnyObject {
func tapRetryButton()
}
class RetryViewController: UIViewController {
@IBOutlet weak var titleImageView: UIImageView!
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var sendLabel: UILabel! {
didSet {
sendLabel.isUserInteractionEnabled = true
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapSendLabel))
sendLabel.addGestureRecognizer(tapGesture)
}
}
weak var delegate: RetryViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension SlideViewController: EmptyViewDelegate {
func tapOneMoreChance() {
let vc = RetryViewController()
vc.delegate = self
present(vc, animated: true, completion: nil)
}
}
extension SlideViewController: RetryViewControllerDelegate {
func tapRetryButton() {
let ran = Int.random(in: 0...9)
if ran == 1 || ran == 5 || ran == 9 {
let index = ran / 2
emptyView.isHidden = true
matchView.configure(imageURL: data[index])
matchView.isHidden = false
}
}
}