2012-05-27 37 views
0

我正在创建一个UIScrollView子类。在这个子类中,我需要检测滚动事件,但我也想启用对代理上滚动事件的检测。而且,这个UIScrollView子类需要一个自定义委托。UIScrollView子类和自定义委托:检测子类和委托上的滚动事件

// CustomScrollView.h 
#import <UIKit/UIKit.h> 
#import "CustomScrollViewDelegate.h" 

@interface CustomScrollView : UIScrollView <UIScrollViewDelegate> { 
    ... 
} 

@property (nonatomic, assign) id <DAGridViewDelegate> delegate; 

... 

@end 

// CustomScrollView.m 
#import "DAGridView.h" 

@implementation DAGridView 

@synthesize delegate; 

- (id)init { 
    self = [super init]; 
    if (self) { 
     ... 
    } 
    return self; 
} 

... 

@end 

// CustomScrollViewDelegate.h 

@class CustomScrollViewDelegate 

@protocol CustomScrollViewDelegate <NSObject, CustomScrollViewDelegate> 

... 

@end 

感谢您的帮助!

如果您需要更多信息,评论!!

回答

0

好了,你可以在init

self.delegate = self; // to have your custom scroll view as its own delegate 

简单说明,并重新命名要实现为CustomDelegate避免问题

新协议的自定义的委托,那么你必须ovveride每种方法的滚动视图在每个方法调用,并添加类似

[customDelegate ovveriddenScrollviewDelegateMethod]; 

的你在你的类中实现,这将是customDelgate,

<UIScrollViewDelegate, CustomScrollViewDelegate> 

并实施一切。