0

I've got a UIButton inside a UITableViewCell which is held in a table, which is owned by my UITableViewController subclass. I'm trying to make use of the feature of target/action pairs where it can bubble up events to its next responder until it finds a responder which can handle the event, but I'm not getting this to work. Some code:

In my table cell, I setup my button like so:

[self.button addTarget:nil action:@selector(doThing) forControlEvents:UIControlEventTouchUpInside];

The button gets added to my cell, and the cell displays just fine in the tableview. Since I've passed nil in for the target, this event should bubble up until it hits my View Controller, which implements -doThing, but it doesn't get called.

I've overriding - (BOOL)canBecomeFirstResponder and return YES both in the cell subclass and in my view controller subclass, but even combined, it still doesn't work.

I've debugged to see that both the button and the view controller are in the same responder chain, yet somehow, the event doesn't seem to make it up.

Any ideas?

jbrennan
  • 11,943
  • 14
  • 73
  • 115
  • Have you considered creating adding a setter for next responder that the table view can set and the cell can return in `nextResponder`? – tapi Sep 25 '13 at 21:14
  • @tapi at that point I might as well just pass a block through or set a delegate. – jbrennan Sep 25 '13 at 21:25
  • Agreed, Just a thought. Is this under iOS7? its behaving as advertised for me on iOS6 – tapi Oct 09 '13 at 16:31
  • EDIT: The responder chain is right but the actions are still not bubbling – tapi Oct 09 '13 at 16:47
  • Second edit: This works for me on iOS6 but not in iOS7. It worked both with and without a sender parameter on the selector. Time for a radar. – tapi Oct 09 '13 at 17:04
  • @tapi oh damn good catch. Yeah this was for iOS 7 only. – jbrennan Oct 12 '13 at 00:39

2 Answers2

2

The selector for an action message needs a parameter. Try calling it doThing: both in your addTarget: code and in the view controller handler.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

What does the cell say its nextResponder is? Are you sure it doesn't bubble up to the UITableView and not the UITableViewController?

Senior
  • 2,259
  • 1
  • 20
  • 31
  • The cell's next responder is some private Apple view class. The tableview is **also** in the responder chain. – jbrennan Sep 25 '13 at 20:47