9

2つのプロトコルが相互に通信しています。それらは同じファイルで定義されています。

@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(id<Protocol2>)delegate;
@end

@protocol Protocol2 <NSObject>
-(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex;
@end

Protocol2後で宣言されることをコンパイラに知らせるためだけに空のプロトコルを宣言するにはどうすればよいですか?

もしProtocol2クラスだったら、前に書いていたでしょう@class Protocol2;

@class Protocol2;
@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(Protocol2*)delegate;
@end

@interface Protocol2 <NSObject>
-(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex;
@end

プロトコルの同様の構造は何ですか?

4

2 に答える 2

13

プロトコルの前方宣言には@protocolを使用します。

@protocol Protocol2;
@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(id<Protocol2>)delegate;
@end

@protocol Protocol2 <NSObject>
-(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex;
@end
于 2012-06-05T08:12:10.027 に答える
1

あなたの問題は、@classキーワードで前方宣言されたプロトコルを持っていることです。@protocolである必要があります。

于 2012-06-05T08:15:05.170 に答える