UITableView inherits UIScrollView and it uses it's own protocol (UITableViewDelegate) for 'delegate' property.
Usually using different delegate name like myDelegate in order to avoiding conflict with UIScrollView's delegate property when creating own view inherits UIScrollView. 

How can I use property name 'delegate' with my own protocol?
Check following codes. 


@protocol MyViewDelegate;

@interface MyView: UIScrollView
@property (nonatomic, weak) id<MyViewDelegate, UIScrollViewDelegate> delegate;

@protocol MyViewDelegate <NSObject, UIScrollViewDelegate>
- (void)myViewDidFinish:(MyView *)sender;


@implementation MyView

@synthesize delegate = _myViewDelegate;

- (id)initWithFrame:(CGRect)frame
    self = [super initWithFrame:frame];
    if (self) {
        [super setDelegate:self]; // do this if you want to implement UIScrollView's delegate

- (void)setDelegate:(id<MyViewDelegate, UIScrollViewDelegate>)delegate
    _myViewDelegate = delegate;

- (void)test
    if (_myViewDelegate && [_myViewDelegate respondsToSelector:@selector(myViewDidFinish:)])
        [_myViewDelegate myViewDidFinish:self];

#pragma mark UIScrollView Delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
    // Do what you want to do


Posted by xiles


This blog is powered by Daum / Skin design by xiles