I got this code from one of Apple's examples:
@protocol SectionHeaderViewDelegate;
@interface SectionHeaderView : UIView {
}
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIButton *disclosureButton;
@property (nonatomic, assign) NSInteger section;
@property (nonatomic, assign) id <SectionHeaderViewDelegate> delegate;
-(id)initWithFrame:(CGRect)frame title:(NSString*)title section:(NSInteger)sectionNumber delegate:(id <SectionHeaderViewDelegate>)aDelegate;
-(void)toggleOpenWithUserAction:(BOOL)userAction;
@end
@protocol SectionHeaderViewDelegate <NSObject>
@optional
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)section;
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)section;
@end
I am confused by some notation. This is my attempt to explain this. Please correct me if I am wrong:
The first @protocol SectionHeaderViewDelegate;announces the start of the protocol for the class SectionHeaderView. A fourth property is id <SectionHeaderViewDelegate> delegate;required for classes that conform to the protocol so that they can do something like instanceOfClass.delegate = self;.
Then after /* comment */I'm not sure why the protocol directive is used again. Is it part of the same protocol? Is this different from the protocol announced in the first half?
Is my explanation and understanding of the code correct?
source
share