Keith Norman Keith Norman - 1 month ago 8
iOS Question

UITableViewCell skipped in responder chain

I'm attempting to trigger an event in a subview of a

UITableViewCell
, and let it bubble up the responder chain and be handled by a custom
UITableViewCell
subclass.

Basically:

SomeView.m (which is a subview of the
UITableViewCell
)

[self.button addTarget:nil action:@selector(someAction:) events:UIControlEventTouchUpInside]


SomeCustomCell.m

- (void)someAction:(id)sender {
NSLog(@"cool, the event bubbled up to the cell");
}


And to test why this wasn't working, I've added the
someAction:
method on the ViewController and the ViewController is the one that ends up handling the event that bubbles up from the table view cell subview, even though the Cell should handle it. I've checked that the Cell is on the responder chain and I've verified that any views on the responder chain both above and below the cell will respond to the event if they implement the
someAction:
method.

What the heck is going on here?

Here's a project that shows it https://github.com/keithnorm/ResponderChainTest Is this expected behavior somehow? I haven't found any documentation stating UITableViewCell's are treated any differently than other UIResponder's.

Answer

The cell seems to ask its table view for permission. To change that you can of course override

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    return [self respondsToSelector:action];
}

Swift 3:

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    return responds(to: action)
}
Comments