最初。これが私のコードです。
paintingView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@protocol PaintingViewDelegate
-(void)makeLine:(CGPoint) touch;
@end
//CLASS INTERFACES:
@interface PaintingView : UIView
{
id <PaintingViewDelegate> delegate;
@private
CGPoint location;
CGPoint previousLocation;
Boolean firstTouch;
}
@property(nonatomic, readwrite) CGPoint location;
@property(nonatomic, readwrite) CGPoint previousLocation;
@property(nonatomic, assign) id <PaintingViewDelegate> delegate;
@end
paintingView.m
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import "PaintingView.h"
//CLASS IMPLEMENTATIONS:
@implementation PaintingView
@synthesize location;
@synthesize previousLocation;
@synthesize delegate;
// Implement this to override the default layer class (which is [CALayer class]).
// We do this so that our view will be backed by a layer that is capable of OpenGL ES rendering.
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
// Handles the start of a touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] anyObject];
firstTouch = YES;
// Convert touch point from UIView referential to OpenGL one (upside-down flip)
location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
[[self delegate]makeLine:location];
}
...
@end
viewController.h
#import "PaintingView.h"
@interface GMViewController : UIViewController <AGSMapViewLayerDelegate, PaintingViewDelegate>
{
PaintingView *painting1;
}
...
@end
viewController.m
...
- (void)viewDidLoad
{
[super viewDidLoad];
painting1 = [[PaintingView alloc] init];
[painting1 setDelegate:self];
}
...
-(void)makeLine(CGPoint) touch
{
NSLog(@"TOUCH");
}
...
@end
私のデリゲート メソッドは呼び出されません。iOS-developer.net リソースの例からデリゲート メソッドを作成しました。コンパイル中にエラーはありません。