Advertisement
Guest User

Untitled

a guest
Sep 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.32 KB | None | 0 0
  1. //на отрисовке предикшенов
  2. if predictionsInfo[i].number == 1 || predictionsInfo[i].number == 2 || predictionsInfo[i].defaultType! != .normal {
  3.     predictionableView.makeBestChoice()
  4. }
  5. predictionableView.updateBet(OBGlobalConstants.minBet)
  6.  
  7.  
  8. //когда жмем next
  9. @IBAction private func didTapNext(_ sender: UIButton) {
  10.     var indexesWithoutChoice = Array<Int>()
  11.     var indexesWithoutBet = Array<Int>()
  12.     for i in 0..<pageControl.numberOfPages {
  13.         let predictionView = predictionsView[i]
  14.         if let predictionTwoOptionsView = predictionView as? OBPredictionTwoOptionsView, predictionTwoOptionsView.currentOptionType == nil {
  15.             indexesWithoutChoice.append(i)
  16.         }
  17.         else if let predictionThreeOptionsView = predictionView as? OBPredictionThreeOptionsView, predictionThreeOptionsView.currentOptionType == nil {
  18.             indexesWithoutChoice.append(i)
  19.         }
  20.        
  21.         if predictionBets[i] < OBGlobalConstants.minBet {
  22.             indexesWithoutBet.append(i)
  23.         }
  24.     }
  25.    
  26.     if indexesWithoutChoice.contains(pageControl.currentPage) {
  27.         OBAlertManager.showMessage(NSLocalizedString("validation_prediction_make_your_choice", comment: ""), handler: nil)
  28.         return
  29.     }
  30.     else if indexesWithoutBet.contains(pageControl.currentPage) {
  31.         let message = String(format: NSLocalizedString("validation_prediction_min_bet", comment: ""), OBGlobalConstants.minBet)
  32.         OBAlertManager.showMessage(message, handler: nil)
  33.         return
  34.     }
  35.     else {
  36.         for i in 0..<pageControl.currentPage {
  37.             if indexesWithoutChoice.contains(i) {
  38.                 OBAlertManager.showMessage(NSLocalizedString("validation_prediction_make_your_choice", comment: ""), handler: nil)
  39.                 showPage(i)
  40.                 return
  41.             }
  42.             else if indexesWithoutBet.contains(i) {
  43.                 let message = String(format: NSLocalizedString("validation_prediction_min_bet", comment: ""), OBGlobalConstants.minBet)
  44.                 OBAlertManager.showMessage(message, handler: nil)
  45.                 showPage(i)
  46.                 return
  47.             }
  48.         }
  49.     }
  50.    
  51.     if let index = predictionsView.index(where: {type(of: $0) == OBPredictionScoreView.self}), index <= pageControl.currentPage, verifyScore() == false {
  52.         OBAlertManager.showMessage(NSLocalizedString("validation_predictions_wrong_score_value", comment: ""), handler: nil)
  53.         showPage(index)
  54.         return
  55.     }
  56.    
  57.     let nextPage = pageControl.currentPage + 1
  58.     nextPage == pageControl.numberOfPages ?
  59.         showConfirmPredictionsAlert() :
  60.         showPage(nextPage)
  61. }
  62.  
  63.  
  64.  
  65. //проверка счета
  66. private func verifyScore() -> Bool {
  67.     var result = true
  68.     if let scoreView = predictionsView.first(where: {type(of: $0) == OBPredictionScoreView.self}) as? OBPredictionScoreView, match.type! == .tennis {
  69.         let countMaxScore = scoreView.currentScore.map { String($0) }.filter { $0 == String(scoreView.maxScore) }.count
  70.         result = countMaxScore == 1 ? true : false
  71.     }
  72.     return result
  73. }
  74.  
  75.  
  76.  
  77.  
  78. //после загрузки предикшенов
  79. if self?.predictionsInfo[0].defaultType! == .luxe {
  80.     self?.showPage((self?.pageControl.numberOfPages)! - 1)
  81.     self?.showConfirmPredictionsAlert()
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement