Objective-c – warning:’UIResponder’ may not respond to ‘-manageTouches:’

cocoa-touchiphoneobjective c

this is my program .

//Interface file.
#import <Foundation/Foundation.h>
@interface reportView : UIView {

}
- (void)touchesBegan: (NSSet *)touches withEvent: (UIEvent *)event;
- (void)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event;
- (void)touchesMoved: (NSSet *)touches withEvent: (UIEvent *)event;
@end

//ImplementationFile.
#import "reportView.h"

@implementation reportView

- (void) touchesBegan: (NSSet *)touches withEvent: (UIEvent *)event{
    [self.nextResponder manageTouches:touches];
}
- (void) touchesEnded: (NSSet *)touches withEvent: (UIEvent *) event{
    [self.nextResponder manageTouches:touches];
}
- (void) touchesMoved: (NSSet *)touches withEvent: (UIEvent *)event{
    [self.nextResponder manageTouches:touches];
}
@end

I am getting the warning.
warning:'UIResponder' may not respond to '-manageTouches:'
I got 3 warnings as above.

I am getting the needed output correctly but how to resolve the warnings.

Best Answer

First, since your code looks exactly like listing 14.2 from iPhone in Action, did you remember to copy the code for -manageTouches: from listing 14.3 into your class?

Assuming that you did, the issue is that the nextResponder property points to an instance of UIResponder, which could be just about anything (your class, a window, some other OS-managed thing....), and the compiler doesn't know for sure that this particular responder implements a method -manageTouches:. Your options are basically to either live with the warning, or cast the value of nextResponder to your class. (FWIW, the bottom of page 247 mentions this.)

For that matter, you don't really know, at runtime, that the next responder will respond to that message. To be on the safe side, you might want to use -respondsToSelector: or -isKindOfClass: to validate that assumption.

Related Topic