Skip to content

Instantly share code, notes, and snippets.

@BurakDizlek
Last active October 24, 2022 22:48
Show Gist options
  • Select an option

  • Save BurakDizlek/88c23e842723a185e68d6588ea6b435f to your computer and use it in GitHub Desktop.

Select an option

Save BurakDizlek/88c23e842723a185e68d6588ea6b435f to your computer and use it in GitHub Desktop.
Swift Tableview Cell Click Event
var items = [MyModelClass]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell") as! TableCell
let position = indexPath.row
let item = items?[position]
//click event for label
let labelRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tableViewLabelClick))
cell.Label?.isUserInteractionEnabled = true
cell.Label?.addGestureRecognizer(labelRecognizer)
return cell
}
@objc func tableViewLabelClick(sender : UITapGestureRecognizer){
let tapLocation = sender.location(in: tableView)
let indexPath = self.tableView.indexPathForRow(at: tapLocation)
let position = indexPath?.row ?? 0
let item = items?[position]
}
@BurakDizlek
Copy link
Copy Markdown
Author

BurakDizlek commented Jun 27, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment