improved setNextResponder assignment

This commit is contained in:
daboe01
2025-07-05 16:13:50 +02:00
parent 2add37983d
commit d1acff5b44
+9 -6
View File
@@ -258,12 +258,14 @@ var CPViewControllerCachedCibs;
[self loadView];
if (_view)
[_view setNextResponder:self];
if (_view == nil && [cibOwner isKindOfClass:[CPDocument class]])
[self setView:[cibOwner valueForKey:@"view"]];
// If the view was just loaded, we must set its next responder.
// This is the first half of inserting the controller into the responder chain.
if (_view)
[_view setNextResponder:self];
if (!_view)
{
var reason = [CPString stringWithFormat:@"View for %@ could not be loaded from Cib or no view specified. Override loadView to load the view manually.", self];
@@ -412,6 +414,7 @@ var CPViewControllerCachedCibs;
_view = aView;
// When the view is set manually, we must set its next responder.
if (_view)
[_view setNextResponder:self];
@@ -423,10 +426,9 @@ var CPViewControllerCachedCibs;
/*!
@method nextResponder
Returns the receivers next responder.
@discussion The CPViewController implementation of this method returns the superview
of the view controller's view. This effectively inserts the view controller
into the responder chain between its view and the view's superview.
of the view controller's view. This is the second half of the insertion,
completing the chain: view -> viewController -> superview.
*/
- (id)nextResponder
{
@@ -484,6 +486,7 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey",
if (self)
{
_view = [aCoder decodeObjectForKey:CPViewControllerViewKey];
// When the view is unarchived, we must also set its next responder.
if (_view)
[_view setNextResponder:self];