According to the iOS documentation, the responder chain is used to pass touch events "up the chain". It's also used for actions generated by controls. Fine.
What I really would like to do is send a custom event "up the chain". The first responder to pick up on the event will handle it. This seems like a pretty common pattern, but I can't find any good explanation on how to do it the "iOS/Cocoa way".
Since the responder chain is exactly what I need, I came up with a solution like this:
// some event happened in my view that
// I want to turn into a custom event and pass it "up":
UIResponder *responder = [self nextResponder];
while (responder) {
if ([responder conformsToProtocol:@protocol(ItemSelectedDelegate)]) {
[responder itemSelected:someItem];
break;
}
responder = [responder nextResponder];
}
This works perfectly, but I have a feeling that there should be other ways of handling this. Walking the chain manually this way doesn't seem very... nice.
Note that notifications are not a good solution here, because I only want the objects in the view hierarchy to be involved, and notifications are global.
What's the best way of handling this in iOS (and Cocoa for that matter)?
EDIT:
What do I want to accomplish?
I have a view controller, which has a view, which has subviews etc... Several of the subviews are of a specific type that show an item from the database. When the user taps this view, a signal should be sent to the controller to navigate to a detail page of this item.
The view that handles the tap is several levels below the main view in the view hierarchy. I have to tell the controller (or in some cases a specific subview "up the chain") that an item was selected.
Listening to notifications would be an option, but I don't like that solution because selecting an item is not a global event. It's strictly tied to the current view controller.