Reputation: 3740
My custom delegate does not receive a call. Here is my setup. ViewController
has a SliderView
object which is a subclass of UIScrollView
:
SlideView.h
#import <UIKit/UIKit.h>
@protocol SlideViewDelegate <NSObject
@required
-(void) didTapImageData:(NSMutableArray*)imageData atIndex:(int)index;
@end
@interface SliderView : UIScrollView<UIGestureRecognizerDelegate> {
__weak id<SlideViewDelegate> slideViewDelegate;
}
@property (nonatomic, weak) id<SlideViewDelegate> slideViewDelegate;
@end
SlideView.m
#import "SliderView.h"
@implementation SliderView
@synthesize slideViewDelegate;
- (void) handleTap:(UITapGestureRecognizer *)recognizer{
NSLog(@"tapped");
[[self slideViewDelegate] didTapImageData: imageData atIndex:0 ];
}
ViewController.h
@interface ViewController : UIViewController <
UIScrollViewDelegate,
SlideViewDelegate>{
SliderView *thumbGalleryView;//delegate and reference are set in XCode
}
ViewController.m
#import "ViewController.h"
@implementation ViewController
-(void)didTapImageData:(NSMutableArray*) imageData atIndex:(int)index{
NSLog(@"NOT WORKING HERE");
}
So ViewController
never receives a call at the method above. The thumbGalleryView
is linked to ViewController
and delegate is set to ViewController
too. SlideView
's handleTap
is printing message fine but [[self slideViewDelegate] didTapImageData: imageData atIndex:0 ];
is ignored. Why?
Upvotes: 2
Views: 139
Reputation: 39998
You have set the delegate
which is ivar
of scroll view.
You have to set the slideViewDelegate
to ViewController
Edited
Add IBOutlet
IBOutlet __weak id<SlideViewDelegate> slideViewDelegate;
Then from your xib connect slideViewDelegate
to ViewController
Also remember to change the class of scroll view to SliderView
Added Image for clarity
Upvotes: 1
Reputation: 60150
Double-check where you set your delegate - if your delegate is nil
at the time -handleTap:
calls your -didTapImageData:atIndex:
method, nothing will happen.
Upvotes: 1