Search code examples
objective-cuitableviewios7uiaccessoryview

Distinguishing taps on UITableViewCell in general from taps on its accessory button in particular


I would like to implement a UITableViewController that works in a similar fashion to the Episodes (under the My Podcasts) view in the iOS 7 Podcasts app in that its cells should perform one segue if I tap on the (left part of the) cell and perform another segue if I tap on the cell's accessory view.

My UITableViewController implements both tableView:didSelectRowAtIndexPath: and tableView:accessoryButtonTappedForRowWithIndexPath: from UITableViewDelegate, however only the former method gets called, regardless of whether I tap on a cells accessory button or somewhere else inside the cell.

So how can the necessary distinction be made. I assume it would be possible to place a UITapGestureRecognizer on the cell's contentView and use its event handler instead of tableView:didSelectRowAtIndexPath:, but hope there is a simpler scheme as well.


Solution

  • I have meanwhile found what appears to be the right answer here:

    iOS will make a distinction and call either tableView:didSelectRowAtIndexPath: or tableView:accessoryButtonTappedForRowWithIndexPath: if the accessory (as set in IB) is a detail disclosure button (or detail button), but not if it is a disclosure indicator. Indeed Apple's Podcasts app uses a detail button in the described context.

    This is the relevant excerpt from (an older version of) the documentation:

    Note that the detail disclosure button, unlike the disclosure indicator, can perform an action that is separate from the selection of the row.