我使用UIScrollView
的自定義子類ImageScrollView
。我需要知道用戶何時點擊滾動視圖,所以我創建了一個協議。我在我的RootViewController
中執行協議,一切看起來都很好。當我建了,那裏有一個警告自定義協議的設置委託干擾UIScrollViewDelegate方法
班「ImageScrollView」不落實「TapDetectingImageViewDelegate」協議」。
在ImageScrollView
類檢查init
方法後,我看到self.delegate = self;
引起問題我宣佈自己是UIScrollView
代表方法的代表,但我也是我自己的協議的代表(代表我的協議必須是RootViewController
,而不是ImageScrollView
)
- (id)initWithFrame:(CGRect)frame{
if ((self = [super initWithFrame:frame])) {
self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;
self.bouncesZoom = YES;
self.decelerationRate = UIScrollViewDecelerationRateFast;
self.delegate = self;
}
return self;
}
你們知道我該如何解決這個問題嗎?或者告訴我的RootViewController
該用戶已點擊UIScrollView
/UIImage
更好的主意。
在ImageScrollView.h協議聲明類的
@protocol TapDetectingImageViewDelegate <NSObject>
@optional
- (void)tapDetectingImageView:(ImageScrollView *)view gotSingleTapAtPoint:(CGPoint)tapPoint;
@end
頭文件實現在實現它
的.m類它#import <UIKit/UIKit.h>
#import "ImageScrollView.h"
@interface AppleScrollViewViewController : UIViewController <UIScrollViewDelegate, TapDetectingImageViewDelegate>{
UIScrollView *pagingScrollView;
}
-(void)configurePage:(ImageScrollView *)page forIndex:(NSUInteger)index;
- (CGRect)frameForPageAtIndex:(NSUInteger)index;
- (CGRect)frameForPagingScrollView;
- (UIImage *)imageAtIndex:(NSUInteger)index;
- (NSString *)imageNameAtIndex:(NSUInteger)index;
- (CGSize)imageSizeAtIndex:(NSUInteger)index;
- (NSArray *)imageData;
@end
協議方法
-(void)tapDetectingImageView:(ImageScrollView *)view gotSingleTapAtPoint:(CGPoint)tapPoint{ NSLog(@"SingleTap"); }
你可以發佈你的協議聲明和.h實現協議的類嗎?這聽起來像協議中方法聲明的簽名和實現不匹配。 – highlycaffeinated 2011-06-08 16:20:10
當我發佈你問的東西時,發現我在我的課上實施了錯誤的協議方法。我實施了正確的方法並記錄了「單擊」。但我仍然收到警告。任何想法? – Canelo 2011-06-08 16:48:19