Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Amplitude_iOS
- class JHACategoriesController: UIViewController {
- @IBOutlet var tableView: UITableView!
- var games: NSMutableArray! = NSMutableArray()
- var pro = UserDefaults.standard.bool(forKey: "isUpgraded")
- override func viewDidLoad() {
- super.viewDidLoad()
- self.games.removeAllObjects()
- self.games.add(["Lett blanding", "game-icon-free"])
- self.games.add(["Alle spørsmål", "game-icon-shuffle"])
- self.games.add(["Harmløs","game-icon-harmless"])
- self.games.add(["Reise","game-icon-travel"])
- // self.games.add(["Fadderuke!","game-icon-fadderuke"])
- self.tableView.reloadData()
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(true)
- pro = UserDefaults.standard.bool(forKey: "isUpgraded")
- self.tableView.reloadData()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
- func tableView(_ tableView: UITableView, numberOfSectionsInTableView indexPath: IndexPath) -> Int {
- //@objc func numberOfSectionsInTableView(_ tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection indexPath: IndexPath) -> Int {
- //@objc func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return games.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- //@objc func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
- let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
- let gameName:String = (self.games.object(at: indexPath.row) as AnyObject).object(at: 0) as! String
- let imageName:String = (self.games.object(at: indexPath.row) as AnyObject).object(at: 1) as! String
- cell.gameLabel.text = gameName
- cell.imageLeft.image = UIImage(named: imageName)
- if pro {
- cell.imageRight.isHidden = true
- } else {
- cell.imageRight.isHidden = false
- }
- if indexPath.row == 0 {
- cell.imageRight.isHidden = true
- }
- cell.separatorInset = UIEdgeInsetsMake(0, 0, cell.frame.size.width, 0)
- cell.layoutMargins = UIEdgeInsets.zero
- cell.preservesSuperviewLayoutMargins = false
- return cell
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- //@objc func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
- tableView.deselectRow(at: indexPath, animated: true)
- if (indexPath.row > 0 && pro == false) {
- self.presentUpgrade()
- return
- }
- self.startNewGame("blanding", indexPath: indexPath)
- }
- func tableView(_ tableView: UITableView,
- heightForFooterInSection section: Int) -> CGFloat {
- //@objc func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return CGFloat.leastNormalMagnitude
- }
- func presentUpgrade() {
- let vc:UIViewController
- vc = (self.storyboard?.instantiateViewController(withIdentifier: "Upgrade"))!
- self.present(vc, animated: true, completion: nil)
- }
- func startNewGame(_ identifier: String, indexPath: IndexPath) {
- // Bruk idenitifer for å skille spørsmålene
- let vc:JHAGameController = (self.storyboard?.instantiateViewController(withIdentifier: "JHAGameController"))! as! JHAGameController
- vc.modalTransitionStyle = .crossDissolve
- vc.identifier = identifier
- var amplitudeIdentifier = ""
- if indexPath.row == 0 {
- // LETT BLANDING - Gratis
- vc.questions = freeQuestions as NSArray
- amplitudeIdentifier = "Blanding"
- } else if (indexPath.row == 1) {
- // Alle spørsmål
- let array = freeQuestions+harmlessQuestions+dirtyQuestions+travelQuestions+movieQuestions+bliKjentQuestions+norgeRundtQuestions
- vc.questions = array as NSArray
- // allQuestions as NSArray
- amplitudeIdentifier = "Alle spørsmål"
- } else if (indexPath.row == 2) {
- // Harmløs
- vc.questions = harmlessQuestions as NSArray
- amplitudeIdentifier = "Harmløs"
- } else if (indexPath.row == 3) {
- // Dirty
- vc.questions = dirtyQuestions as NSArray
- amplitudeIdentifier = "Reise"
- }
- self.present(vc, animated: true, completion: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment