I am creating an application using Swift. I have a UITableView that I populate with some data from a database. When a user clicks on a cell, I would like to trigger an action.
What I've done:
var array: [String] = ["example"] func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return array.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = UITableViewCell(style :UITableViewCellStyle.Default, reuseIdentifier: "cell") cell.textLabel.text = array[indexPath.row] cell.tag = indexPath.row cell.targetForAction("getAction:", withSender: self) return cell } func getAction(sender:UITableViewCell)->Void { if(sender.tag == 0) { println("it worked") } }
I tried to adapt the solution from another post, but I definitely did it wrong. Thank you in advance
ios uitableview swift
soling
source share