Reputation: 584
according to https://developer.apple.com/library/ios/documentation/General/Conceptual/Devpedia-CocoaApp/Responder.html, "If a view is managed by a view controller and if the view cannot handle an event, the view controller becomes the next responder"
What is meant by this statement? It is possible for a View to internally define a handler for an event and capture it intrinsically? If this is not the case the ViewController for the view will be called if it has explicitly defined a handler for the event?
It seems contrary to the MVC pattern for the View to handle events - or is the documentation really saying a handler on a controller specific to the View is invoked?
Upvotes: 0
Views: 357
Reputation: 535067
There is a responder chain, formed by each UIResponder's nextResponder()
:
The UIView that we start with.
If this UIView is a UIViewController's view
, that UIViewController. (This is what the passage you quoted is saying.)
The UIView's superview.
Go back to step 2 and repeat! Keep repeating until we reach...
The UIWindow.
The UIApplication.
The UIApplication's delegate.
Certain messages are sent, not so much to a particular object, but up the responder chain. We start with a particular object, but if that object doesn't have an implementation for the method, we don't crash; instead, we walk the responder chain, looking for someone further up the chain who does have an implementation for the method. Moreover, if we never find such an implementation, we do not crash; the message falls off the end of the chain without penalty.
There are two chief messages of this sort:
Touch events.
Nil-targeted actions.
As to your question, what does this have to do with MVC...? Nothing. As Josh Gafni's answer rightly says, MVC is not the only pattern in the world. This is about responders, not about MVC.
Upvotes: 2
Reputation: 2881
UIView
actually already has event handlers that you can overwrite. You can subclass UIView
and handle touch events using the following methods:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
There are two ways of communication between the View and View Controller. In general, the View Controller typically tells the View what to display, and the View tends to call delegate methods when events occur. I do understand though that you would typically expect these event handlers to be called by the View but handled in the View Controller. But...
UIView
and they are specifically related to the View.Upvotes: 0