When I add a UIView subclass object to a UIView – for example a UISwitch inside a prototype UITableViewCell and I connect this switch with a ViewController via IBAction, how can I find out in this action which table row is the invoked UISwitch in?
I attached the image just to be clear – when the UISwitch is invoked, I want to know which row the invoked UISwitch is in.

I think the “cleanest” way to do this is to have the switch send its action to the cell itself. You’ll need to subclass UITableViewCell to implement that action, and have it pass itself along to a method on the view controller (probably by giving the cell a delegate the view controller is hooked up to). This is a fair amount of pomp; there are more straight-forward but less proper methods below.
One way is to specify a
tagon the UISwitch when configuring the table view cell in the first place (i.e. in yourtableView:cellForRowAtIndexPath:method). Something likeswitch.tag = indexPath.row; you can then retrieve the row from the switch later by asking it for its tag.Another way is to search upwards through the UISwitch’s superviews until you find a UITableViewCell and then find its row. Something like: