Search code examples
iphoneios5delegatesuiscrollviewuiscrollviewdelegate

UIScrollView subclass and custom delegate: detect scroll events on the subclass and on the delegate


I'm creating an UIScrollView subclass. On this subclass, I need to detect the scroll events, but I also want to enable the detection of scroll events on a delegate. Also, this UIScrollView subclass needs a custom delegate.

// 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

Thanks for helping!!

If you need some more information, comment!!


Solution

  • well, you can simply state in the init

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

    and rename your custom delegate of the new protocol you are implementing as CustomDelegate to avoid problem

    then you must ovveride each method the scroll view calls and in each method add something like

    [customDelegate ovveriddenScrollviewDelegateMethod];
    

    The you implement in your class which will be the customDelgate,

    <UIScrollViewDelegate, CustomScrollViewDelegate>
    

    and implement enverything.