I have a UITableView with custom Cell (subclass of UITableViewCell). Each cell view has two buttons btn1 and btn2. I set my ViewController to handle the TouchUp Inside of those btn1s.
How do I know in which cell button clicked?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d put a tag property on it. Say the left one has a tag of 1, and the right has a tag of 2.
All UIViews have a tag property, which is just an integer value.
Then when you have received a button tap, you can ask what the button’s tag is – 1 or 2, and you’ll know which button it was.
If you want to know which index path that button belonged to, you can grab the button’s superview, which should be the cell, or the button’s superview’s superview, if you placed it on the cell’s content view (as you generally should):
Note that the above code assumes the button was placed directly on the cell.