我有两个view controllers A
和B
,他们都拥有对方作为自己的代表.
当我除了在头文件的开头和#import
另一个头文件中定义协议之外什么都没做的时候,我得到两个错误 -
找不到"BDelegate"的协议声明,它在Ah(我写的地方)中显示无法找到"ADelegate"的协议声明,这是在Bh(我写的地方)中显示的
在线查看,人们早些时候写过,包含头文件的循环包含可能会导致问题.他们建议使用#include
相反,或@class
声明像 -
@class A
Run Code Online (Sandbox Code Playgroud)
代替
#import A.h
Run Code Online (Sandbox Code Playgroud)
内 #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
--------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
- BaseViewController.h -
#<UIKit/UIKit.h>
#import "BigViewController.h"
#include "BigViewController.h"
@class BigViewController;
@protocol …
Run Code Online (Sandbox Code Playgroud) 我的代码以前很好,但它提示我:
cannot find protocol declaration for 'CAAnimationDelegate';did you mean 'UIApplicationDelegate'?
Run Code Online (Sandbox Code Playgroud)
我今天跑的时候.
我尝试过导入QuartzCore/CAAnimation.h
但不起作用.
有两个协议,每个协议都在自己的文件中:
// PMAService.h
#import <Foundation/Foundation.h>
#import "PMAPost.h"
#import "PMAServiceProcessingDelegate.h"
@protocol PMAService <NSObject>
-(void)setupService;
-(BOOL)processPost:(PMAPost *)post withDelegate:(id<PMAServiceProcessingDelegate>)delegate;
@end
// PMAServiceProcessingDelegate.h
#import <Foundation/Foundation.h>
#import "PMAPost.h"
#import "PMAService.h"
@protocol PMAServiceProcessingDelegate <NSObject>
-(void)successfullyProcessedPost:(PMAPost *)post by:(id<PMAService>)service;
-(void)notProcessedPost:(PMAPost *)post by:(id<PMAService>)service withError:(NSError *)error;
@end
Run Code Online (Sandbox Code Playgroud)
每个协议都需要与方法声明相反.一旦我在每个文件中创建导入,编译器就不能再编译,因为它告诉我它找不到其中一个协议.
PMAService.h
(对于#import语句PMAServiceProcessingDelegate.h
)的错误消息
错误消息PMAServiceProcessingDelegate.h
(每个方法声明一个):
有什么我错过了吗?不允许导入这样的协议吗?