我有两个视图控制器A和B,它们都将对方定义为自己的代理。
当我除了在头文件开头定义协议并导入其他头文件之外什么都没做时,我收到两个错误,类似于-
无法找到"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