簡體   English   中英

找不到協議聲明

[英]Protocol declaration not being found

所以我有一類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'? Cannot find protocol declaration for 'CommentViewControllerDelegate'; did you mean 'UISplitViewControllerDelegate'?

我想念什么嗎? 我總是在協議和委托方面遇到麻煩。

您的包含文件中有一個循環。

CommentViewController.h刪除此行:

#import "FirstViewController.h"

該頭文件中未引用它,如果已引用,則可以簡單地輸入:

@class FirstViewController;

而不是包含整個文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM