Guest User

Code

a guest
Jun 3rd, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 5.20 KB | None | 0 0
  1. import UIKit
  2. import Amplitude_iOS
  3.  
  4. class JHACategoriesController: UIViewController {
  5.  
  6.     @IBOutlet var tableView: UITableView!
  7.    
  8.     var games: NSMutableArray! = NSMutableArray()
  9.    
  10.     var pro = UserDefaults.standard.bool(forKey: "isUpgraded")
  11.    
  12.     override func viewDidLoad() {
  13.         super.viewDidLoad()
  14.  
  15.         self.games.removeAllObjects()
  16.        
  17.         self.games.add(["Lett blanding", "game-icon-free"])
  18.         self.games.add(["Alle spørsmål", "game-icon-shuffle"])
  19.         self.games.add(["Harmløs","game-icon-harmless"])
  20.         self.games.add(["Reise","game-icon-travel"])
  21.         // self.games.add(["Fadderuke!","game-icon-fadderuke"])
  22.        
  23.         self.tableView.reloadData()
  24.        
  25.     }
  26.    
  27.     override func viewDidAppear(_ animated: Bool) {
  28.         super.viewDidAppear(true)
  29.        
  30.         pro = UserDefaults.standard.bool(forKey: "isUpgraded")
  31.        
  32.         self.tableView.reloadData()
  33.        
  34.     }
  35.  
  36.     override func didReceiveMemoryWarning() {
  37.         super.didReceiveMemoryWarning()
  38.        
  39.     }
  40.    
  41.     func tableView(_ tableView: UITableView, numberOfSectionsInTableView indexPath: IndexPath) -> Int {
  42.     //@objc func numberOfSectionsInTableView(_ tableView: UITableView) -> Int {
  43.         return 1
  44.     }
  45.    
  46.     func tableView(_ tableView: UITableView, numberOfRowsInSection indexPath: IndexPath) -> Int {
  47.     //@objc func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  48.         return games.count
  49.     }
  50.    
  51.    
  52.     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  53.     //@objc func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
  54.         let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
  55.        
  56.         let gameName:String = (self.games.object(at: indexPath.row) as AnyObject).object(at: 0) as! String
  57.         let imageName:String = (self.games.object(at: indexPath.row) as AnyObject).object(at: 1) as! String
  58.        
  59.         cell.gameLabel.text = gameName
  60.         cell.imageLeft.image = UIImage(named: imageName)
  61.        
  62.         if pro {
  63.             cell.imageRight.isHidden = true
  64.         } else {
  65.             cell.imageRight.isHidden = false
  66.         }
  67.        
  68.         if indexPath.row == 0 {
  69.             cell.imageRight.isHidden = true
  70.  
  71.         }
  72.  
  73.         cell.separatorInset = UIEdgeInsetsMake(0, 0, cell.frame.size.width, 0)
  74.         cell.layoutMargins = UIEdgeInsets.zero
  75.         cell.preservesSuperviewLayoutMargins = false
  76.    
  77.        
  78.         return cell
  79.     }
  80.    
  81.     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  82.     //@objc func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
  83.        
  84.         tableView.deselectRow(at: indexPath, animated: true)
  85.  
  86.         if (indexPath.row > 0 && pro == false) {
  87.            
  88.             self.presentUpgrade()
  89.             return
  90.            
  91.         }
  92.        
  93.         self.startNewGame("blanding", indexPath: indexPath)
  94.        
  95.     }
  96.    
  97.     func tableView(_ tableView: UITableView,
  98.                    heightForFooterInSection section: Int) -> CGFloat {
  99.     //@objc func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  100.        
  101.         return CGFloat.leastNormalMagnitude
  102.        
  103.     }
  104.    
  105.     func presentUpgrade() {
  106.        
  107.         let vc:UIViewController
  108.         vc = (self.storyboard?.instantiateViewController(withIdentifier: "Upgrade"))!
  109.         self.present(vc, animated: true, completion: nil)
  110.        
  111.     }
  112.  
  113.     func startNewGame(_ identifier: String, indexPath: IndexPath) {
  114.        
  115.         // Bruk idenitifer for å skille spørsmålene
  116.        
  117.         let vc:JHAGameController = (self.storyboard?.instantiateViewController(withIdentifier: "JHAGameController"))! as! JHAGameController
  118.         vc.modalTransitionStyle = .crossDissolve
  119.        
  120.         vc.identifier = identifier
  121.         var amplitudeIdentifier = ""
  122.        
  123.         if indexPath.row == 0 {
  124.            
  125.             // LETT BLANDING - Gratis
  126.             vc.questions = freeQuestions as NSArray
  127.             amplitudeIdentifier = "Blanding"
  128.            
  129.            
  130.         } else if (indexPath.row == 1) {
  131.            
  132.             // Alle spørsmål
  133.            
  134.             let array = freeQuestions+harmlessQuestions+dirtyQuestions+travelQuestions+movieQuestions+bliKjentQuestions+norgeRundtQuestions
  135.            
  136.             vc.questions = array as NSArray
  137.                 // allQuestions as NSArray
  138.             amplitudeIdentifier = "Alle spørsmål"
  139.            
  140.            
  141.         } else if (indexPath.row == 2) {
  142.            
  143.             // Harmløs
  144.             vc.questions = harmlessQuestions as NSArray
  145.             amplitudeIdentifier = "Harmløs"
  146.            
  147.            
  148.         } else if (indexPath.row == 3) {
  149.            
  150.             // Dirty
  151.             vc.questions = dirtyQuestions as NSArray
  152.             amplitudeIdentifier = "Reise"
  153.            
  154.         }
  155.        
  156.         self.present(vc, animated: true, completion: nil)
  157.        
  158.        
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment