How can I attach an object to a control/UIView in iOS so that I can clearly know which control I’m dealing with?
The scenario is I have a UITableView that is ‘bound’ to an array of strings. I have a custom control (UISwitch) in the cell that sometimes triggers the removal of the row/cell.
In the call back (set by calling addTarget on my UISwitch) I have no way of knowing which cell triggered the event.
Is there a property on UISwitch that I could use to indicate this. Ideally I could attach the original datasource object. In Microsoft technologies, controls often have a tag property that can hold a reference to anything (object/id). However, the tag property in Cocoa Touch is an NSUInteger which doesn’t really help – because storing the index doesn’t work once you’ve deleted an item from the middle of the array; everything is out of sync.
You can get the tableview cell by using the view hierarchy.
So in you switch action