I have a button inside a custom cell. When tapped the button presents a view via a modal segue.
So, here’s my question, in the prepareForSegue:sender: I want to pull the indexPath of the cell which contains that button(sender) that I pushed. How do I get that cell’s indexPath?
I thought I could do something like:
UITableViewCell * cell = sender.parent
Obviously it doesn’t work that way.
Please help me out.
UPDATE Thanks to @rmaddy I’ve tried [[sender superview] superview] and got to the cell in which the button was held and to it’s indexPath. Thanks for your answers guys!
Assuming
senderis aUIVIewof some sort (such as aUIButton), then:If you are positive that the button’s superview is the table cell then you can do:
Once you have the cell, use the table view’s
indexPathForCell:method.Keep in mind that if you actually added the button to the cell’s
contentViewor some other subview of the cell, then getting the cell from the button is a bit trickier.