Reputation: 1
I'm trying to create my own custom UIScrollView, so that I can pass touch events from it to a delegate object which has logic to draw to an imageview inside the scrollview.
If I remove the delegate variable and property from the class interface it works fine as a normal scroll view. When I make it my custom protocol delegate it builds but doesn't pass on messages..
Any help appreciated
@class DrawableScrollView;
@protocol DrawableScrollViewDelegate <UIScrollViewDelegate>
- (void)touchesBegan:(DrawableScrollView *)drawableScrollView touches:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(DrawableScrollView *)drawableScrollView touches:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(DrawableScrollView *)drawableScrollView touches:(NSSet *)touches withEvent:(UIEvent *)event;
@end
@interface DrawableScrollView : UIScrollView {
id<DrawableScrollViewDelegate> delegate;
}
@property (nonatomic, assign) IBOutlet id<DrawableScrollViewDelegate> delegate;
@end
Upvotes: 0
Views: 1052
Reputation: 94844
Chances are that the UIScrollView methods that pass on the delegate messages use the (private) ivar to access the delegate, rather than using the property accessor each time. So when you override those with your own delegate property, the underlying scrollview delegate never gets set.
One way around this would be to use the UIScrollView's implementation of delegate
and setDelegate:
to store your delegate, instead of or in addition to using your own ivar. Another would be to rename your property to avoid the conflict. A third would be to make the view inside the scrollview respond to the touches, rather than messing with the scrollview itself.
Upvotes: 1