我有两个view controllers A
和B
,它们彼此都有自己的代理。
当我除了在头文件的开头定义协议和#import
对方的头文件之外什么也不做时,我得到了两个关于以下内容的错误:
找不到"BDelegate“的协议声明,它显示在A.h (我写的地方)找不到"ADelegate”的协议声明,它显示在B.h (我写的地方)
在网上看一看,人们早些时候写道,头文件的循环包含可能导致了问题。他们建议使用#include
,或者像这样的@class
声明-
@class A
而不是
#import A.h
#import B.h
内幕
我尝试了几乎所有这些导入的组合,以及@classes
和#include
,但仍然无法摆脱警告。此外,在线解决方案建议将#import
移动到.m
文件,但这也没有帮助。部分原因是网上的解决方案有点模糊--如果你能把它分解一下,那就太好了。
有什么建议可以解决这个问题吗?
-- BigViewController.h --
#import "BaseViewController.h"
#include "BaseViewController.h"
@class BigViewController;
@protocol BigViewControllerDelegate
-(void) BigViewController:(BigViewController *) bigView;
@end
@interface BigViewController : UIViewController <BaseViewControllerDelegate>
{
//delegate
id <BigViewControllerDelegate> delegate;
ivars...
}
@properties...
@end
--------------------------------------------------
-- BaseViewController.h --
#<UIKit/UIKit.h>
#import "BigViewController.h"
#include "BigViewController.h"
@class BigViewController;
@protocol BaseViewControllerDelegate
- (void) setParametersWithItemChosen:(Item *) item;
@end
@interface BaseViewController : UIViewController <...BigViewControllerDelegate...>
{
ivars...
//delegate
id <BaseViewControllerDelegate> delegate;
}
@properties...
@end
https://stackoverflow.com/questions/6447573
复制相似问题