Home Firebase: Pass data from different Table Views in Detail View Controller
Reply: 0

Firebase: Pass data from different Table Views in Detail View Controller

dan Published in 2017-11-14 20:05:13Z

I Found it mostly with users and single table views.

Scenario: I have two tableViews with some Add button(tableViewLeft and TableViewRight) Where I want to add different players time in a different sections inside FirebaseDB(called Team A and Team B).

How can I create and show different unique data in the details View Controller, for every Indexpath.Row?

I am not sure if I set up my creation and player Class correctly.

MY Player Class

class PlayerClass: NSObject {
var name:String?
var age:Int?
var height:Int?
var nationality:String?
var position:String?

let newPlayer = [[String:Any]]()

init(name: String?, age: Int?, height: Int?, nationality: String?, position: String?) {

    self.name = name
    self.age = age
    self.height = height
    self.nationality = nationality
    self.position = position


playersDetails VC

class PlayerDetails:UIViewController {

@IBOutlet weak var playerName: UILabel!
@IBOutlet weak var playerAge: UILabel!
@IBOutlet weak var playerHeight: UILabel!
@IBOutlet weak var playerNationality: UILabel!


How I insert data in Firebase

func insertNewPlayerInLeftTeam() {

    if textFieldLeft.text!.isEmpty {
        print("Add Text Before!")
    } else {

    ref = Database.database().reference()

    let key = ref.childByAutoId().key

    var player : PlayerClass = PlayerClass(name: textFieldLeft.text! as String, age: 20 , height: 100, nationality: "italian",position:"CEN")

        let newPlayer = ["id": key,
                         "playerName": textFieldLeft.text! as String,
                         "age":player.age as! Int,
                         "height": player.height as! Int,
                         "nationality": player.nationality as! String,
                         "position":player.position as! String
            ] as [String : Any]



    let indexPath = IndexPath(row: teamA.players.count - 1, section: 0)

    tableViewLeft.insertRows(at: [indexPath], with: .automatic)

    textFieldLeft.text = ""

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330927 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO