IOS 5.0 Warning: Cannot find protocol definition for delegate

I have a custom UIView GestureView class. I have a forward declaration for this class, and it is presented below. I imported GestureView.h into a .m file. This works great, but iOS gives a warning that "Cannot find the protocol definition for GestureViewDelegate." If I delete the forward declaration, it gives the same warning as the error. I do not want to import GestureView.h from ContainerViewController.h, since I usually import material into a .m file. Can someone explain what is wrong in the following class structure?

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 
+6
source share
2 answers

I like that you are trying to avoid importing in header files: a very good practice. However, to fix your mistake, you can simply make your code even better! In my opinion, it is not necessary for your ContainerViewController class to externally claim that it supports the GestureViewDelegate protocol, so you must transfer it to your implementation file. For instance:

Gestureview.h

 #import <UIKit/UIKit.h> @protocol GestureViewDelegate; @interface GestureView : UIView - (void)initialiseGestures:(id <GestureViewDelegate>)delegate; @end @protocol GestureViewDelegate <NSObject> @required - (void)gestureView:(GestureView *)view handleSingleTap:(UITapGestureRecognizer *)recognizer; @end 

ContainerViewController.h

 #import <UIKit/UIKit.h> @class GestureView; @interface CollectionViewController : UIViewController // this property is declared as readonly because external classes don't need to modify the value (I guessed seen as it was an IBOutlet) @property (strong, nonatomic, readonly) GestureView *topContentView; @end 

ContainerViewController.m

 #import "ContainerViewController.h" #import "GestureView.h" // this private interface declares that GestureViewDelegate is supported @interface CollectionViewController () <GestureViewDelegate> // the view is redeclared in the implementation file as readwrite and IBOutlet @property (strong, nonatomic) IBOutlet GestureView *topContentView; @end @implementation ContainerViewController // your implementation code goes here @end 
+21
source

Try this path and answer if it works or not.

Gestureview.h

 #import <UIKit/UIKit.h> @protocol GestureViewDelegate <NSObject> @required - (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer; @end @interface GestureView : UIView - (void)initialiseGestures:(id)delegate; @end 

ContainerView.h

 #import <UIKit/UIKit.h> @class DividerView; @class GestureView; /*@protocol GestureViewDelegate;*/ //NO NEED TO WRITE THIS @interface ContainerViewController : UIViewController<GestureViewDelegate> @property (strong, nonatomic) IBOutlet GestureView *topContentView; @end 
0
source

Source: https://habr.com/ru/post/927724/


All Articles