Search code examples
iosobjective-cuitableviewpushviewcontroller

Push Detail View from UITableView only on a specific UIImage in the cell?


I've got a UITableView which pushes a detail view when I tap any of its cells. I'd like that segue to only occur when tapping a specific part of the cell, a UIImageView at its left side. Tapping the rest of the cell should trigger a UITapGestureRecognizer which triggers a different method.

How can I override the default tap on the UITableViewCell, so that simply tapping anywhere on the cell doesn't trigger the segue to the detail view? I still want that transition, just only triggered by the UIImageView.


Solution

  • I think you could achieve that by connecting the segue with the image in the prototype cell (Never tried that myself) and not with the table view.

    If you don't have a prototype cell then you should programmatically invoke an IBAction type of method with the image views. Well, Image Views cannot do that. Simply abuse a UIButton of the same size, custom style and assign the image to that button. Works fine. (It does not need to be an -(IBAction) type of method, but it does not harm and doing so ensures that everything works fine.)

    Within that action method invoke the segue programmatically. The segue needs to have an ID for that which is unique within the storyboard.