I have one table view within the app that I hope multiple parts of the app would be able to use to post updates to the table view with possible actions that the user can take. One of the ways that I thought of implementing this is via a large enum, with a switch statement with the table view. In this case, the table view would be performing an action based on the enum value for the table cell. This requires knowledge of the classes involved, and seems overly complicated.
There has to be a better way. Is it possible to use selectors with a target for the UITableViewCell accessory button?
I think that for regular buttons and navbar buttons I can do something like this:
[thisIconBtn addTarget:self action:@selector(changeIconState:) forControlEvents:UIControlEventTouchUpInside];
is there an equivalent way of assigning an action to the UITableView accessory? Or should I stick with the large enum?
thank you!
Unfortunately, the
accessoryActionof aUITableViewCellis deprecated as of iOS 3.0.From the UITableViewCell Reference Docs:
However, if your accessory view inherits from
UIControl(UIButton, etc), you may set a target and action through theaddTarget:action:forControlEvents:method.Something like this (modify to fit your needs):
Or, the more traditional route (I’m not positive, but I believe your question states that this is what you are trying to avoid. You can ignore this block of code if that is true.):