I am trying to implement when user click the tableView
cell, that selected cell
value need to pass
detail viewcontroller
. Here, the transition
connection I made by storyboard
(not programmatically) and present modally transition I used.
I would like to know how to do, so provide some example.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// here I need implement get selected index path and passing values to another vc
}
Use preparefor(segue:)
as follows,
I'm assuming few thing
PlayerDetailsVC
.Players
model, which are you showing in the tableview.single selection
.Based on these assumption your code will be like following
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let indexPath = tableView.indexPathForSelectedRow{
let selectedRow = indexPath.row
let PlayerDetailsVC= segue.destination as! DetailViewController
let member = "\(players[selectedRow].name ?? "")"
PlayerDetailsVC.player = member
}
}
In DetailViewcontroller
need to do below
var player:String? //print it within viewdidload