Last active
October 24, 2022 22:48
-
-
Save BurakDizlek/88c23e842723a185e68d6588ea6b435f to your computer and use it in GitHub Desktop.
Swift Tableview Cell Click Event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} |
Author
BurakDizlek
commented
Jun 27, 2019
via email
Teşekkür ederim çekirge, çok doğru :)
bahadirerdemm <[email protected]>, 27 Haz 2019 Per, 15:24 tarihinde
şunu yazdı:
… cell.Label?.addGestureRecognizer(UITapGestureRecognizer(target: self,
action: #selector(youFunc)))
ile daha kısa bir onClick eventi setleyebilirsin.
cell.Label?.tag = indexPath.row
ile de tıklanılan label'ın position'ınını alabilirsin.
(Çekirgen)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/88c23e842723a185e68d6588ea6b435f?email_source=notifications&email_token=ADHRGZZHDV2XE4JXAZ4PE3LP4SWOHA5CNFSM4H33NC2KYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFUMR6#gistcomment-2955551>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADHRGZ7KVFCOIGC5O2BUHUDP4SWOHANCNFSM4H33NC2A>
.
--
Saygılarımla ,
İyi Çalışmalar ...
Burak Dizlek
Bilgisayar Mühendisi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment