Reputation: 1579
I found some answer that quite solve my questions, but seems that I'm missing some steps. I'm just trying to intercept the "ViewDidBlablabla" events of a ScrollView, so I created a custom UIScrollView class.
#import "MyScrollView.h"
@implementation MyScrollView
- (id)initWithFrame:(CGRect)frame{
NSLog(@"initWithFrame");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)scrollViewWillBeginDragging:(UIScrollView*)scrollView{
NSLog(@"scrollViewWillBeginDragging");
//scrollView.contentOffset
}
-(void)scrollViewDidScroll:(UIScrollView*)scrollView{
NSLog(@"scrollViewDidScroll");
}
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
NSLog(@"scrollViewDidEndScrollingAnimation");
}
@end
#import <UIKit/UIKit.h>
@interface MyScrollView : UIScrollView <UIScrollViewDelegate>
@end
When I alloc my custom Scroll View I do get the console message "initWithFrame", but there's no way to get to the other events. What am I missing?
If you need some other pieces of code feel free to ask, but since I get to my custom "initWithFrame" method, I suppose that the error should be here.
Upvotes: 2
Views: 2579
Reputation: 726479
Try setting your view as the delegate of itself:
if (self) {
// Initialization code
self.delegate = self;
}
Technically, you do not need to inherit UIScrollView
to respond to scrolling events: it is sufficient to set the delegate
to an implementation of <UIScrollViewDelegate>
.
Also, the scrollViewDidEndScrollingAnimation:
method has been gone for about two years, so it is not going to be called on modern iOS installations.
Upvotes: 4