У меня есть ViewController с ScrollView SubView, и у этого подпредставления есть подпредставление, ниже приведена иерархия:
AppDelegate - MyViewController - ScrollView (из xib) - MyScrollViewSubClass
// MyViewController:
// .h
@interface MyViewController : UIViewController<MyScrollViewSubClassDelegate,UIScrollViewDelegate> {
UIScrollView *scrollView; // Loaded from xib
}
@property(nonatomic,retain) IBOutlet UIScrollView *scrollView;
@end
// .m
@implementation MyViewController
@synthesize scrollView;
- (void)viewDidLoad {
[super viewDidLoad];
scrollView.delegate = self;
MyScrollViewSubClass *myScrollView = [[MapScrollView alloc] init];
myScrollView.delegate = self;
myScrollView.myDelegate = self;
scrollView addSubview:mapScrollView];
}
// The MyScrollViewSubClassDelegate @required method
- (void) onDoubleTapLocation: (CGPoint)tapPoint
{
// Working,,,NSLog shown that this line is Working...
}
// MyScrollViewSubClass + Delegate
// .h
// Protocol
@protocol MyScrollViewSubClasswDelegate <NSObject>
@required
- (void) onDoubleTapLocation: (CGPoint)tapPoint;
@end
//Interface
@protocol MyScrollViewSubClass;
@interface MyScrollViewSubClass : UIScrollView <UIScrollViewDelegate> {
id <MyScrollViewSubClasswDelegate> myDelegate;
// Another vars..
}
@property (nonatomic,assign) id<MyScrollViewSubClasswDelegate> myDelegate;
- (void)handleDoubleTap;
@end
// .m
@implementation MyScrollViewSubClass
@synthesize myDelegate;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
// Another Code Here...
self.delegate = self; // delegate for UIScrollView
self.myDelegate = self;
//Another Code Here...
}
return self;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(isDoubleTap)
{
//Call handle double tap
[self handleDoubleTap];
}
}
- (void)handleDoubleTap {
[self.myDelegate onDoubleTapLocation: tapLocation];
}
Что происходит, так это то, что двойное касание работает на MyViewController, но теперь я не могу прокручивать и масштабировать мой MyScrollViewSubClass из MyViewController, приветствуются любые критические замечания, комментарии или лучший метод.
Решено:
Я назначаю делегата на MyViewController дважды
было:
myScrollView.delegate = self;
myScrollView.myDelegate = self;
Должно быть:
myScrollView.myDelegate = self;
С уважением,
Паром Хаттавидиан