Last active
April 26, 2020 11:59
-
-
Save primofin/486efb3847238074872c84720aa1e115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ScoreTableViewController.swift | |
| // geoapp | |
| // | |
| // Created by nguyen thanh vy on 25/04/2020. | |
| // Copyright © 2020 team geo app. All rights reserved. | |
| // | |
| import UIKit | |
| import Firebase | |
| class UserScoreTableViewController: UITableViewController{ | |
| var ref:DatabaseReference! | |
| var databaseHandle:DatabaseHandle? | |
| var scoresArray = [Any]() | |
| var usernameArray = [Any]() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| //Set the firebase reference | |
| ref = Database.database().reference() | |
| ref.child("scores").observe(.value, with: { (snapshot) in | |
| let score = snapshot.value as! NSDictionary | |
| self.scoresArray.append(score.allValues) | |
| self.usernameArray.append(score.allKeys) | |
| self.tableView.reloadData() | |
| }) | |
| } | |
| // MARK: - Table view data source | |
| override func numberOfSections(in tableView: UITableView) -> Int { | |
| return 1 | |
| } | |
| override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
| return scoresArray.count | |
| } | |
| override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| guard let cell = tableView.dequeueReusableCell(withIdentifier: "scoreItemCell", for: indexPath) as? UserScoreTableViewCell else { | |
| fatalError("The dequeued cell is not an instance of UserScoreTableViewCell.") | |
| } | |
| cell.textLabel?.text = scoresArray[indexPath.row] as? String | |
| return cell | |
| } | |
| /* | |
| // Override to support conditional editing of the table view. | |
| override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { | |
| // Return false if you do not want the specified item to be editable. | |
| return true | |
| } | |
| */ | |
| /* | |
| // Override to support editing the table view. | |
| override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { | |
| if editingStyle == .delete { | |
| // Delete the row from the data source | |
| tableView.deleteRows(at: [indexPath], with: .fade) | |
| } else if editingStyle == .insert { | |
| // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view | |
| } | |
| } | |
| */ | |
| /* | |
| // Override to support rearranging the table view. | |
| override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { | |
| } | |
| */ | |
| /* | |
| // Override to support conditional rearranging of the table view. | |
| override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { | |
| // Return false if you do not want the item to be re-orderable. | |
| return true | |
| } | |
| */ | |
| /* | |
| // MARK: - Navigation | |
| // In a storyboard-based application, you will often want to do a little preparation before navigation | |
| override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
| // Get the new view controller using segue.destination. | |
| // Pass the selected object to the new view controller. | |
| } | |
| */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment