I have a view controller that has three scroll views as subviews. I would like to have the child scrolling views inform the parent view controller whenever the page has changed.
I thought I would do this by setting up a delegation pattern. My child (a subclass of UIScrollView) sets it up in the header file:
@interface TriptychScrollView : UIScrollView <UIScrollViewDelegate> {
id delegate;
}
- (id)delegate;
- (void)setDelegate:(id)newDelegate;
@end
@protocol RCScrollDidChange
@optional
- (void)scrollView:(TriptychScrollView *)scrollView imageDidChange:(NSNumber *)index;
@end
The source file has the delegate accessor methods:
- (id)delegate {
return delegate;
}
- (void)setDelegate:(id)newDelegate {
delegate = newDelegate;
}
Unfortunately, this means my setting the delegate to self call is being ignored:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setDelegate:self];
}
return self;
}
.. and therefore the two methods scrollViewDidScroll: and scrollViewDidEndDecelerating: are not getting called! This means I've effectively lost control of my scrolling views.
Am I doing this incorrectly? Or is there a better way for the child subviews to send messages back to their parents?