Skip to content

Instantly share code, notes, and snippets.

@sebastienwindal
Created June 29, 2017 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastienwindal/55c17c34cbe97a4cc6e253dc3685fb5d to your computer and use it in GitHub Desktop.
Save sebastienwindal/55c17c34cbe97a4cc6e253dc3685fb5d to your computer and use it in GitHub Desktop.
index path from cell or button inside a cell in prepareforsegue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
var indexPath:IndexPath? = nil
if let cell = sender as? UITableViewCell {
indexPath = tableView.indexPath(for: cell)
}
if let button = sender as? UIButton {
let buttonFrame = button.convert(button.bounds, to:tableView)
indexPath = tableView.indexPathForRow(at: buttonFrame.origin)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment