2

我的自定义委托没有接到电话。这是我的设置。ViewController有一个SliderView对象,它是 的子类UIScrollView

幻灯片视图.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

幻灯片视图.m

#import "SliderView.h"
@implementation SliderView
@synthesize slideViewDelegate;

- (void) handleTap:(UITapGestureRecognizer *)recognizer{
    NSLog(@"tapped");
   [[self slideViewDelegate] didTapImageData: imageData atIndex:0 ];
}

视图控制器.h

@interface ViewController : UIViewController <
                                        UIScrollViewDelegate,
                                        SlideViewDelegate>{
   SliderView *thumbGalleryView;//delegate and reference are set in XCode
}

视图控制器.m

#import "ViewController.h"
@implementation ViewController

-(void)didTapImageData:(NSMutableArray*) imageData atIndex:(int)index{
    NSLog(@"NOT WORKING HERE");
}

所以ViewController永远不会收到上述方法的电话。thumbGalleryView链接到并且ViewController委托也设置为ViewControllerSlideViewhandleTap打印消息很好,但[[self slideViewDelegate] didTapImageData: imageData atIndex:0 ];被忽略了。为什么?

4

2 回答 2

1

仔细检查您设置委托的位置 - 如果您的委托nil当时-handleTap:调用您的-didTapImageData:atIndex:方法,则不会发生任何事情。

于 2012-12-20T17:21:12.143 回答
1

您已设置delegate哪个是ivar滚动视图。

您必须slideViewDelegateViewController


已编辑

添加IBOutlet

IBOutlet __weak id<SlideViewDelegate> slideViewDelegate;

然后从您的xib连接slideViewDelegateViewController
还记得将滚动视图的类更改为SliderView
添加图像以清楚起见 在此处输入图像描述

于 2012-12-20T17:42:00.877 回答