I'm trying to transfer a tableview cell from my hockeydetailVC to my favouritesVC using a button and I can't transfer it due to some issue.
My hockeydetailVC
I'm trying to transfer my item object
My favouritesVC
I have a segue for my button so I have this
If the transfer works then my sendData() method up top would print a statement but my addToFav only prints "favourite button pressed".
My hockeydetailVC
Code Block protocol addThis { func addFav(data: CurrentPlayers) }
I'm trying to transfer my item object
Code Block var item: CurrentPlayers? var delegate: addThis? = nil
Code Block func sendData() { if delegate != nil { let data = item! delegate?.addFav(data: data) print("This is the data being transferred: \(data)") } } @IBAction func addToFav(_ sender: Any) { sendData() print("Favourite button Pressed") }
My favouritesVC
Code Block var currentFav: CurrentPlayers?
Code Block func addFav(data: CurrentPlayers) { currentFav = data }
I have a segue for my button so I have this
Code Block override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "r" { let hockeyDetailVC: HockeyDetailVC = segue.destination as! HockeyDetailVC hockeyDetailVC.delegate = self } }
If the transfer works then my sendData() method up top would print a statement but my addToFav only prints "favourite button pressed".