I have subclassed a UIScrollView to customize it a bit. I am trying to create a delegate that will notify several other classes that a user has done a certain thing in the UIScrollView. In my UIScrollView class I have the code below. The problem I am running into is I am getting the warning
Property ‘delegate’ ‘retain (or strong)’ attribute does not match the
property inherited from ‘UIScrollView’
I see that this is because my Class in inheriting from UIScrollView, but my delegate is conforming to the NSObject. This is the first time I tried creating my own delegate. What can I do to fix this?
My Code:
#import <UIKit/UIKit.h>
@protocol ChangeSpaceDelegate <NSObject>
- (void)changeSpace:(int)spaceId;
@end
@interface CustomUIScrollView : UIScrollView {
id<ChangeSpaceDelegate> delegate;
}
@property (retain, nonatomic)id delegate;
@end
To answer your question specifically, you are redefining the property attribute on the
delegateproperty you get fromUIScrollView. It should, like all delegates, beweak(or, pre-iOS 5,unsafe_unretained).However, you shouldn’t do it this way.
UIScrollViewalready has a delegate, and if you expect to put your own delegate object implementing your new delegate methods into it, the inner workings ofUIScrollViewaren’t going to be happy. Define a new protocol and a new delegate property for it.