I\'m trying to get index
of selected item in TableView
and start some activity after that. Unfortunately most of solutions that I found are in obje
I screw up on the every time! Just make sure the tableView
delegate and dataSource
are declared in viewDidLoad
. Then I normally populate a few arrays to simulate returned data and then take it from there!
//******** Populate Table with data ***********
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? SetupCellView
cell?.ControllerLbl.text = ViewContHeading[indexPath.row]
cell?.DetailLbl.text = ViewContDetail[indexPath.row]
cell?.StartupImageImg.image = UIImage(named: ViewContImages[indexPath.row])
return cell!
}
Problem was solved by myself using tutorial of weheartswift
In Swift 3.0
You can find the event for the touch/click of the cell of tableview through it delegate method. As well, can find the section and row value of the cell like this.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("section: \(indexPath.section)")
print("row: \(indexPath.row)")
}