未找到协议声明

时间:2012-03-20 16:38:29

标签: objective-c delegates protocols

所以我有一个班级CommentViewController.h我有

#import "FirstViewController.h"

@protocol CommentViewControllerDelegate;

@interface CommentViewController : UIViewController {
id <CommentViewControllerDelegate> delegate;
}

 @property (nonatomic, assign) id <CommentViewControllerDelegate> delegate;

- (IBAction)submit:(id)sender;

-(IBAction)cancel:(id)sender;

 @end

@protocol CommentViewControllerDelegate
-(void)commentViewControllerDidFinish:(CommentViewController *)controller;
@end

我在实现中合成了委托

我尝试访问FirstViewController.h中的协议:

 #import "CommentViewController.h"
 @interface FirstViewController : UIViewController <CommentViewControllerDelegate>

植入FirstViewController

 - (void)commentViewControllerDidFinish:(CommentViewController *)controller {
 [self dismissModalViewControllerAnimated:YES];
 }

此行显示错误:

@interface FirstViewController : UIViewController <CommentViewControllerDelegate>

错误:Cannot find protocol declaration for 'CommentViewControllerDelegate'; did you mean 'UISplitViewControllerDelegate'?

我错过了什么吗?我总是遇到协议和代理问题。

1 个答案:

答案 0 :(得分:7)

您的包含文件中有一个循环。

CommentViewController.h

中删除此行
#import "FirstViewController.h"

它没有在头文件中引用,如果是,你可以简单地把:

@class FirstViewController;

而不是包含整个文件。