Sto creando un'app utilizzando Swift. Ho un UITableView
che compilo con alcuni dati da un database. Quando l'utente fa clic su una cella, vorrei attivare un'azione.Attiva un'azione quando un utente fa clic su una cella in rapido
quello che ho fatto:
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")
}
}
ho cercato di adattare una soluzione da un altro post, ma l'ho fatto sicuramente sbagliato. Grazie in anticipo
Grazie, è perferct! – soling
non dimenticare di implementare il protocollo 'UITableViewDelegate' per ottenere il metodo' didSelectRowAtIndexPath' – LynAs