<Cannot find protocol declaration>
来源:互联网 发布:2017年交通事故数据 编辑:程序博客网 时间:2024/05/17 03:54
47down vote
Let me reduce the sample even further, and label the lines:
VC1.h
#import "VC2.h" // A@class VC1;@protocol VC1Delegate // B@end@interface VC1 : UIViewController <VC2Delegate> // C@end
VC2.h
#import "VC1.h" // D@class VC2;@protocol VC2Delegate // E@end@interface VC2 : UIViewController <VC1Delegate> // F@end
Consider what happens when something #imports VC1.h: It reaches line A, then the import is processed. Line D does nothing because VC1.h was already imported. Then line E is processed. Then line F, and we get an error because we haven't gotten to line B yet so the protocol is not declared!
Consider then what happens when something #imports VC2.h: It reaches line D, then the import is processed. Line A does nothing because VC2.h was already imported. Then line B is processed. Then line C, and we get an error because we haven't gotten to line E yet so the protocol is not declared!
The first step is to reconsider whether both of these classes really need to be each other's delegates. If you can break the cycle, that would probably be the way to go. If not, you'll need to restructure your headers. The most straightforward way is probably to put the delegates into their own headers:
VC1Delegate.h
@class VC1;@protocol VC1Delegate // B@end
VC1.h
#import "VC1Delegate.h"#import "VC2Delegate.h"@interface VC1 : UIViewController <VC2Delegate> // C@end
VC2Delegate.h
@class VC2;@protocol VC2Delegate // E@end
VC2.h
#import "VC1Delegate.h"#import "VC2Delegate.h"@interface VC2 : UIViewController <VC1Delegate> // F@end
If you trace through the imports now, you'll see that the appropriate protocols will now always be declared before the @interface lines try to use them.
http://stackoverflow.com/questions/6447573/cannot-find-protocol-declaration
- <Cannot find protocol declaration>
- Delegate Cannot find protocol declaration
- cannot find protocol declaration for "RefreshAudioListViewDelegate"
- cannot find protocol declaration for "RefreshAudioListViewDelegate”
- ios error:Cannot find protocol declaration for
- cannot find protocol declaration for "xxDelegate" 的错误
- cocos2d 2.1使用Sneakyinput报错Cannot find protocol declaration for CCTargetTouchDelegate/CCStandardTouch
- Cannot find the declaration of element 'beans'
- Cannot find the declaration of element 'beans'
- pycharm Cannot find declaration to go to
- Cannot find the declaration of element 'beans'
- Cannot find the declaration of element 'beans'
- idea cannot find declaration to go to
- Cannot find protocol definition for 'TencentSessionDelegate'
- cannot find protocol definition for 'TencentSessionDelegate'
- Cannot find the declaration of element 'beans'. 的解决方法
- Static Library: Cannot find interface declaration for 'UIImage'
- Cannot find the declaration of element 'beans'. 的解决方法
- view Scroller 分析
- java基础加强
- openFlashChat
- QT遍历目录获取文件信息
- Oracle中分区表的使用
- <Cannot find protocol declaration>
- android 最新 NDK r8 在window下开发环境搭建 安装配置与使用 详细图文讲解,完整实际配置过程记录
- SQL触发器实例讲解
- 读“浪潮之巅”精华备忘
- “加一”项目总结--android使用篇(二)(转)
- asp.net服务器控件button先执行js再执行后台的方法
- Uninstall GOM Player with WindowsUninstaller.Org Removal Tips
- 应用层的poll 函数介绍
- 如何查看http请求和返回,浏览器和服务器沟通的过程