我有一个带ScrollView SubView的ViewController,那些子视图中有一个子视图,下面是层次结构:
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];
}
Happen是双击是在MyViewController上工作,但现在我无法从MyViewController滚动和捏缩我的MyScrollViewSubClass,欢迎任何评论家,评论或更好的方法..
已解决:
我在 MyViewController 上分配了两次委托
是:
myScrollView.delegate = self;
myScrollView.myDelegate = self;
应该是:
myScrollView.myDelegate = self;
问候,
Ferry Hattawidian
答案 0 :(得分:0)
我在MyViewController上分配了两次委托
是:
myScrollView.delegate = self;
myScrollView.myDelegate = self;
应该是:
myScrollView.myDelegate = self;
其他一切运行良好......谢谢你们......