【发布时间】:2014-01-13 18:32:00
【问题描述】:
我在尝试添加第二个协议时遇到问题。第一个工作得很好。所以我创建了一个测试应用程序来尝试使用两种协议(因为我还在学习如何使用协议)。我不知道为什么我在理解协议时遇到这么多麻烦。我什至已经完成了教程,但仍在努力学习。
当我尝试添加第二个协议并使用它时,我的第一个问题收到以下错误:
从不兼容的类型“*const _strong”分配给“id”
但是,让我们暂时忽略它,因为我的测试应用程序在我的测试应用程序中的两种协议都给我这个错误:
找不到协议声明
因此,我将发布我的测试应用程序的代码,因为在解决更困难的问题之前,我必须了解基础知识。
DelegateA 标头
#import <Foundation/Foundation.h>
@protocol IDDelegateADelegate <NSObject>
@end
@interface IDDelegateA : NSObject
//other properties here
@property (nonatomic, assign) id<IDDelegateADelegate> delegateA;
@end
DelegateA 实施
#import "IDDelegateA.h"
@implementation IDDelegateA
@synthesize delegateA;
//other methods and properties go here
@end
DelegateB 标头
#import <Foundation/Foundation.h>
@protocol IDDelegeteBDelegate <NSObject>
@end
@interface IDDelegeteB : NSObject
//other properties here
@property (nonatomic, assign) id<IDDelegeteBDelegate> delegateB;
@end
DelegateB 实施
#import "IDDelegeteB.h"
@implementation IDDelegeteB
@synthesize delegateB;
//other methods and properties go here
@end
使用这些委托的测试类 Header
#import <Foundation/Foundation.h>
#import "IDDelegateA.h"
#import "IDDelegeteB.h"
@interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>
@end
就在这里,我收到了两个代表的Cannot find protocol declaration 错误。我一直在搜索 SO 以及浏览教程和示例代码。 SO的最佳答案是here。但我只是不明白我做错了什么。有人可以指出我在这里缺少什么吗?
【问题讨论】:
-
轻微拼写错误,您在其标题和实现中有
IDDelegeteB,但您在测试类中引用了IDDelegateB...在继续进行之前更正所有拼写错误是个好主意。 -
是的,我知道这一定是非常愚蠢的事情。谢谢。
标签: objective-c protocols