-1

第一的。这是我的代码。

绘画视图.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

绘画视图.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

视图控制器.h

#import "PaintingView.h"

@interface GMViewController : UIViewController <AGSMapViewLayerDelegate, PaintingViewDelegate>
{
PaintingView *painting1;
}
...
@end

视图控制器.m

...
- (void)viewDidLoad
{
[super viewDidLoad];

painting1 = [[PaintingView alloc] init];
[painting1 setDelegate:self];
}
...
-(void)makeLine(CGPoint) touch
{
NSLog(@"TOUCH");
}
...
@end

我的委托方法永远不会被调用。我从 iOS-developer.net 资源示例中创建了我的委托方法。编译过程中没有错误。

4

1 回答 1

1

通过使用我的类文件paintingView's中的行设置委托来 修复它。[painting setDelegate: self];viewController

于 2012-08-28T14:36:37.523 回答