Guest User

Untitled

a guest
Jan 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  2. let dn = arrData[indexPath.row]
  3. cell.fav_btn.tag = dn.id
  4. cell.fav_btn.addTarget(self, action: #selector(checkMarkButtonClicked(sender:)), for: .touchUpInside)
  5. }
  6.  
  7. @objc func checkMarkButtonClicked ( sender: UIButton) {
  8. print("button presed")
  9. let buttonTag = sender.tag
  10. print(buttonTag)
  11.  
  12. }
  13.  
  14. class CustomTableViewCell: UITableViewCell {
  15. var buttonAction: (() -> Void)?
  16. }
  17.  
  18. fav_btn.addTarget(self, action: #selector(checkMarkButtonClicked(sender:)), for: .touchUpInside)
  19.  
  20. @objc func checkMarkButtonClicked (sender: UIButton) {
  21. if let myAction = buttonAction {
  22. myAction()
  23. }
  24.  
  25. }
  26.  
  27. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  28.  
  29. // ваша логика
  30.  
  31. cell.buttonAction = { [weak self] in
  32. self?.someMethod()
  33. }
  34. }
Add Comment
Please, Sign In to add comment