【发布时间】:2012-10-15 09:10:53
【问题描述】:
我有自定义 UIView 类 GestureView。我有这个类的前向声明,它是下面的代表。我在 .m 文件中导入了 GestureView.h。这工作正常,但 iOS 发出警告消息说“找不到 GestureViewDelegate 的协议定义”。如果我删除前向声明,它会给出与错误相同的警告消息。我不想从 ContainerViewController.h 导入 GestureView.h,因为我通常会在 .m 文件中导入东西。有人可以解释一下类结构有什么问题吗?
ContainerViewController.h
#import <UIKit/UIKit.h>
@class DividerView;
@class GestureView;
@protocol GestureViewDelegate;
@interface ContainerViewController : UIViewController<GestureViewDelegate>
@property (strong, nonatomic) IBOutlet GestureView *topContentView;
@end
GestureView.h
#import <UIKit/UIKit.h>
@protocol GestureViewDelegate;
@interface GestureView : UIView
- (void)initialiseGestures:(id)delegate;
@end
@protocol GestureViewDelegate <NSObject>
@required
- (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer;
@end
【问题讨论】:
-
你的协议是在哪里定义的?
-
您可以在我发布的代码中看到!它在 GestureView.h 中!
-
在
ContainerViewController.h尝试#import GestureView.h而不是前向声明 -
我提到我不想那样做!如果您知道前向声明有什么问题,请告诉我。谢谢。
标签: objective-c ios5 protocols forward-declaration