我正在尝试通过在另一个类接口文件中实现委托来实现委托,如下所示:
ImageScrollView.h
#import <UIKit/UIKit.h>
@protocol ImageScrollViewDelegate <NSObject>
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (void)scrollViewDidZoom:(UIScrollView *)scrollView;
@end
@interface ImageScrollView : UIScrollView <UIScrollViewDelegate>
{
id <ImageScrollViewDelegate> _imageScrollViewDelegate;
}
@property(nonatomic, assign) id <ImageScrollViewDelegate> imageScrollViewDelegate;
@end
图像滚动视图.m
#import "ImageScrollView.h"
@implementation ImageScrollView
@synthesize imageScrollViewDelegate = _imageScrollViewDelegate;
...
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.imageScrollViewDelegate scrollViewDidScroll:scrollView];
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView;
{
[self.imageScrollViewDelegate scrollViewDidZoom:scrollView];
}
...
@end
然后我有一个实现 ImageScrollViewDelegate 的 viewController:
ViewControllerSubClass.h
#import <UIKit/UIKit.h>
@protocol ImageScrollViewDelegate;
@interface ViewControllerSubClass : UIViewController <ImageScrollViewDelegate> //warning is here
{
}
@end
视图控制器子类.m
#import "ViewControllerSubclass.h"
#import "ImageScrollView.h"
@implementation ViewControllerSubClass
- (void)loadView
{
...
[[self scrollView] setImageScrollViewDelegate:self];
...
- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
...
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
...
}
在@interface@interface ViewControllerSubClass : UIViewController <ImageScrollViewDelegate>
中ViewControllerSubclass.h
,我收到警告:“找不到“ImageScrollViewDelegate”的协议定义四次,但代码仍在工作。
任何人都知道如何摆脱警告,或者如何正确实现委托(更好地使用单独的文件?)。