Why does the 'delegate' option in the Connections Inspector not show for custom classes?
I have defined a delegate protocol in my custom class this way:
#import <Foundation/Foundation.h>
@protocol myProtocol <NSObject>
-(void)myMethod;
@end
@interface MyClass : NSObject {
id<myProtocol> delegate;
}
@property(nonatomic, assign)开发者_运维问答 id<myProtocol> delegate;
@end
Now in Interface Builder, I drag an NSObject on to the 'Objects' area. Set its class to MyClass.
Why does the connections Inspector not show 'delegate' option (like it does for framework classes below)?
You need to specify that it is an IBOutlet
like so:
#import <Foundation/Foundation.h>
@protocol myProtocol <NSObject>
-(void)myMethod;
@end
@interface MyClass : NSObject {
IBOutlet id<myProtocol> delegate;
}
@property(nonatomic, assign) IBOutlet id<myProtocol> delegate;
@end
From UIKit Constants Reference:
- IBOutlet
Identifier used to qualify an instance-variable declaration so that Interface Builder can synchronize the display and connection of outlets with Xcode. Insert this identifier immediately before the variable type in any variable declarations.
精彩评论