Objective c 找不到XXX的协议定义

Objective c 找不到XXX的协议定义,objective-c,protocols,Objective C,Protocols,我首先声明了一个协议,然后使用它。但我收到一条警告“找不到LeveyPopListViewDelegate的协议定义”。 代码如下: @protocol LeveyPopListViewDelegate; @interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource, UITableViewDelegate,UITextFieldDelegate> //the cont

我首先声明了一个协议,然后使用它。但我收到一条警告“找不到LeveyPopListViewDelegate的协议定义”。 代码如下:

@protocol LeveyPopListViewDelegate;

@interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource,   UITableViewDelegate,UITextFieldDelegate>

//the content of LeveyPopListView

@end

@protocol LeveyPopListViewDelegate <NSObject>
//the definition for LeveyPopListViewDelegate
@end
@protocol-LeveyPopListViewDelegate;
@接口LeveyPopListView:UIView
//LeveyPopListView的内容
@结束
@协议LeveyPopListViewDelegate
//LeveyPopListViewDelegate的定义
@结束

如果我首先放置定义
LeveyPopListViewDelegate
,我就不能在协议中使用
LeveyPopListView

我总是这样做:

@class LeveyPopListView;

@protocol LeveyPopListViewDelegate <NSObject>
//the definition for LeveyPopListViewDelegate
@end

@interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource,   UITableViewDelegate,UITextFieldDelegate>

//the content of LeveyPopListView

@end
@class LeveyPopListView;
@协议LeveyPopListViewDelegate
//LeveyPopListViewDelegate的定义
@结束
@接口LeveyPopListView:UIView
//LeveyPopListView的内容
@结束

您必须首先定义协议。试试下面这样

@protocol LeveyPopListViewDelegate <NSObject>
//the definition for LeveyPopListViewDelegate
@end

@interface LeveyPopListView : UIView <LeveyPopListViewDelegate,UITableViewDataSource,   UITableViewDelegate,UITextFieldDelegate>

//the content of LeveyPopListView

@end
@protocol LeveyPopListViewDelegate
//LeveyPopListViewDelegate的定义
@结束
@接口LeveyPopListView:UIView
//LeveyPopListView的内容
@结束

如果你遵循了这篇文章中的好建议,但仍然存在问题,请尝试做一次清理。我为此挠头了一段时间,一次彻底的解决了这个问题

在协议定义中必须使用具体的类名是不寻常的。您应该做的是(在大多数情况下,异常可能会应用…尽管它们是一种不好的气味)使您的类符合协议,并在委托协议定义中使用该类


一个类需要成为自己的委托,这也是一个坏消息。我会仔细修改设计。

我最终抑制了该特定行的所有警告,这并不理想,但效果很好

//前向声明协议(避免循环包含)
@议定书;
#pragma-clang诊断推送
//要消除不准确的“未找到协议定义”警告
#pragma-clang诊断被忽略“-Weverything”
@接口类:NSObject
// 
#pragma-clang诊断流行语

请确保执行“推送和弹出”操作,否则将忽略此文件的所有警告

当我将
Swift
协议导入
Objective C
类时,这种情况发生在我身上。帮助我的是将
*-Swift.h
文件添加到
目标C
类文件中:

#import "MyApp-Swift.h"
并将协议声明为
@objc

@objc protocol VerificationGate

此外,如果您在不同的文件中声明和定义了协议,则必须导入该文件,在这种情况下,转发声明将没有帮助


顺便说一句,永远不要像一些答案所建议的那样抑制警告。

Max\ux:虽然我们过去对代理所做的一些事情现在可以更好地用块来完成,但使用协议有很多原因。您使用的是哪个版本的XCode?XCode版本4.6(4H127)并不重要。。。您的代码对我来说运行良好,没有错误(XCode4.6)-我只是在一些旧版本中尝试过,以防发生更改,但在4.2中也可以-jb但奇怪的是,尽管有警告,它确实有效,对吗?但我想在
协议中使用leveypolistview
leveypolistview delegate您可以使用我发布的内容。这就是forward类声明的要点。非常感谢。但是为什么首先声明协议会收到警告?我从来都无法使前向协议定义起作用,所以我总是按照我发布的那样做。但是我想在协议LeveyPopListViewDelegates中使用LeveyPopListView您可以在协议定义上方前向声明LeveyPopListView。i、 e@class LeveyPopListView;我明白了。非常感谢。这就成功了。因为我使用的是Swift协议,所以这是删除此警告的唯一方法。我还找到了一个很好的来源