Hello everyone i am trying to implement scrollViewDidScroll in a seperate class for a UIScrollview in my ViewController. Does not trigger the method...Any help appreciated.
C8MyProfileScrollView.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface C8MyProfileScrollView : NSObject <UIScrollViewDelegate>
@property (nonatomic, assign) id<UIScrollViewDelegate> myOwnDelegate;
-(void)scrollViewDidScroll:(UIScrollView *)scrollView;
@end
NS_ASSUME_NONNULL_END
C8MyProfileScrollView.m
#import "C8MyProfileScrollView.h"
@implementation C8MyProfileScrollView
-(id)init{
self = [super init];
self.myOwnDelegate = self;
return self;
}
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"scrolling in seperate class");
}
@end
In my viewcontroller i set it like this
C8MyProfileScrollView *profileTopScrollView = [[C8MyProfileScrollView alloc]initWithFrame:self.scrollView.frame];
self.scrollView.delegate=profileTopScrollView.myOwnDelegate;
You're misunderstanding the delegate/protocol pattern.
Quick example...
MyScrollDelegate.h
MyScrollDelegate.m
Example view controller...
ExtScrollDelegateViewController.h
ExtScrollDelegateViewController.m
Scrolling the scroll view will output lots of lines like this: