协议到视图控制器不会触发任何已定义的方法

问题描述:

我创建了一个协议和匹配的委托。 我定义的方法似乎没有触发,但没有发现错误。协议到视图控制器不会触发任何已定义的方法

ResourceScrollView.h

//Top of File 
@protocol ResourceScrollViewDelegate 
    - (void)loadPDFWithItem:(NSString *)filePath; 
@end 
//Within Interface 
id<ResourceScrollViewDelegate> _scrollViewDelegate; 
//Outside Interface 
@property (nonatomic, retain) id<ResourceScrollViewDelegate> scrollViewDelegate; 

ResourceScrollView.m

//Inside Implementation 
@synthesize scrollViewDelegate=_scrollViewDelegate; 
//Within a button tapped method 
[_scrollViewDelegate loadPDFWithItem:filePath]; 

ResourcesViewController.h

//Top of File 
#import "ResourceScrollView.h" 
@interface ResourcesViewController : UIViewController <ResourceScrollViewDelegate> 

ResourcesViewController.m

//Inside Implementation 
- (void)loadPDFWithItem:(NSString *)filePath{ 
    NSLog(@"PDF %@",filePath); 
} 

出于某种原因,我没有得到NSLog。 没有错误或崩溃,它根本不会触发。

我是否犯过可能导致此行为的错误?

您忘记了将ResourcesViewController对象设置为scrollViewDelegate属性吗?

+0

你是什么意思?我将如何做到这一点? – 2012-04-23 09:43:45

+0

啊,没关系,我明白了! '[resourceScrollView setScrollViewDelegate:self];' – 2012-04-23 10:08:03