The UIWebViewDelegate protocol does not declare a method scrollViewDidScroll:
. Hence, this is why you're getting the bad access error.
I'd recommend that you subclass UIWebView
instead of trying to creating a category on it (yes, the docs recommend against subclassing... just don't override any of the methods it has, and it's safe).
On your subclass, you can either create a new protocol or simply overwrite the delegate
property to also require that it conforms to `UIScrollViewDelegate (the later is shown below):
In Example:
// MyWebView.h
#import <UIKit/UIKit.h>
@interface MyWebView : UIWebView
@property (nonatomic, assign) id<UIWebViewDelegate, UIScrollViewDelegate> delegate;
@end
// MyWebView.m
#import "MyWebView.h"
@implementation MyWebView
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
/* As scrollViewDidScroll: is optional, you should check if the super class
responds to this method (it doesn't appear to now, but this may change in future) */
if ([[self superclass] instancesRespondToSelector:@selector(scrollViewDidScroll:)])
{
[super scrollViewDidScroll:scrollView];
}
/* Likewise, you should check if your own delegate responds to this selector */
if ([self.delegate respondsToSelector:@selector(scrollViewDidScroll:)])
{
[self.delegate scrollViewDidScroll:scrollView];
}
}
@end