代理方法没有被调用

问题描述:

我已经看过所有其他问题都有同样的问题,但我似乎无法听到我的消息。我很确定我已经做好了一切,因为这不是我第一次使用代表。代理方法没有被调用

//PDFView.h 
@class PDFView; 

@protocol PDFViewDelegate <NSObject> 
-(void)trialwithPOints:(PDFView*)pdfview; 
@end 

@interface PDFView : UIView 
@property (nonatomic, weak) id <PDFViewDelegate> delegate; 

在实现文件中我试图打电话但从

//PDFView.m 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self.delegate trialwithPOints:self]; 
} 

其中委托方法实现

//points.h 
#import "PDFView.h" 
@interface points : NSObject <PDFViewDelegate> 

//points.m 

//this is where the delegate is set 
- (id)init 
{ 
if ((self = [super init])) 
{ 
     pdfView = [[PDFView alloc]init]; 
     pdfView.delegate = self; 

} 
return self; 
} 

-(void)trialwithPOints:(PDFView *)pdf 
{ 
    NSLog(@"THE DELEGATE METHOD CALLED TO PASS THE POINTS TO THE CLIENT"); 
} 

因此,这是怎样的类touchesMoved委托的委托方法我已经写了我的委托,不知何故委托是零,委托方法永远不会被调用。

目前我没有对委托做任何事情,我只是想看看它的工作。

任何意见,将不胜感激。

+2

你在哪里设置代表? –

+0

对不起,我编辑我的代码..我忘了复制代码,我设置代表。 – fftoolbar

我认为这是因为你没有持有对委托实例的引用,并且因为它被声明为weak而被释放。你可能会这样:

pdfView.delegate = [[points alloc] init]; 

,你应该解决的东西,如:

_points = [[points alloc] init]; 
pdfView.delegate = _points; 

其中_points是实例变量。

+0

这是非常有用的:)。我确实忽略了这一点。 – fftoolbar