cannot find protocol declaration for "RefreshAudioListViewDelegate"
今天一個很變態的問題卡住了:cannot find protocol declaration for "RefreshAudioListViewDelegate"
1.在PlayerController.h自定義了 一個代理 RefreshAudioListViewDelegate
#import "PlayerListViewController.h" @protocol RefreshAudioListViewDelegate <NSObject> - (void) updateCurrentPlayedAudio:(NSUInteger) currentPlayedIndex; @end @interface PlayerController : NSObject
2.在PlayerListViewController.h中
#import "PlayerController.h" @class PlayerController; @interface PlayerListViewController : UIViewController< RefreshAudioListViewDelegate> { PlayerController *playerController; }
編譯器提示“cannot find protocol declaration for "RefreshAudioListViewDelegate”
分析原因:
在編譯器編譯順序:
1.PlayerListViewController.h文件時,首先發現#import "PlayerController.h",編譯器會跑到PlayerController.h中。
2.在PlayerController.h中首先發現#import "PlayerListViewController.h",編譯器又會到PlayerListViewController中加載內容。
3.這時 當見到
@interface PlayerListViewController : UIViewController< RefreshAudioListViewDelegate>這一句的時候,由於在PlayerController中定義代理的語句還沒有加載,所以編譯器會報錯:
cannot find protocol declaration for "RefreshAudioListViewDelegate"
解決辦法:
刪除PlayerController.h中的
#import "PlayerListViewController.h"