ios - Subclass as delegate of superclass -
i have class imageviewcontroller
. has delegate:
@protocol imageviewcontrollerdelegate @optional - (void)singletapgesturerecognizer:(uitapgesturerecognizer *)gesture; - (void)imagedidloaded;
i have class attachmentviewcontroller
subclass of imageviewcontroller
. in class want event image property in changed. here code of change:
- (void)setimage:(uiimage *)image { // * assign image animation [uiview transitionwithview:self.imageview duration:k_duration_imageappearence options:uiviewanimationoptiontransitioncrossdissolve animations: ^{ self.imageview.alpha = 1; } completion:^(bool finished) { if ([self respondstoselector:@selector(imagedidloaded)]) { [self.delegate imagedidloaded]; } }];
but can not use
if ([self.delegate respondstoselector:@selector(imagedidloaded)])
then have error:
no known instance method selector 'respondstoselector:'
why? , how here need use capabilities? implementation ok? or how can notification?
i think here ok create clear methods in superclass , override in subclass if needs implement is. best way?
you should declare protocol @protocol imageviewcontrollerdelegate <nsobject>
this says object conforms protocol conform nsobject
protocol respondstoselector:
declared in.
Comments
Post a Comment