scrollViewDidScroll没有被调用

时间:2013-07-09 23:56:34

标签: objective-c uiscrollview delegates

我有UIViewController,是UIScrollView的{​​{1}}代表。我已将scrollview的委托设置为视图控制器,但只要滚动滚动视图,我就不会调用NumberLineScroll。这是实施:

scrollViewDidScroll:标头文件(UIViewController):

Game

以及实现方法的主文件的组件:

@interface Game : UIViewController <LocDelegate, UIScrollViewDelegate, ResultsDelegate> {
    ... 
    NumberLineScroll* nline;
    ...
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView;
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;

这是- (void)viewDidLoad { ... nline = [[NumberLineScroll alloc] initWithFrame: CGRectMake(0, -50, 1024, 400)]; [nline setScrollEnabled:YES]; [nline setContentSize:CGSizeMake(4100, 400)]; [self.view addSubview:nline]; nline.delegate = self; nline.locDelegate = self; //this is for a Ball imageview that is implemented in NumberLineScroll ... } UIScrollView)的实现:

头文件:

NumberLineScroll

主文件中没有任何相关内容。我做的唯一一个影响滚动的程序是关闭反弹并在用户移动球时关闭滚动,然后在完成时再次打开。此外,@interface NumberLineScroll : UIScrollView { NumberLine* nline; Ball* ball; id <UIScrollViewDelegate> delegate; id <LocDelegate> locDelegate; } @property(nonatomic, assign)id <UIScrollViewDelegate> delegate; @property(nonatomic, assign)id <LocDelegate> locDelegate; 不是问题,因为它可以正常工作。主要问题是locDelegate没有委托调用。这是为什么?

另外,NumberLineScroll中的NumberLine视图是滚动视图的内容视图,仅供澄清。

1 个答案:

答案 0 :(得分:3)

我最好的猜测是,您正在重新定义delegate级内的NumberLineScroll属性。尝试删除@property(nonatomic, assign)id <UIScrollViewDelegate> delegate;行(如果* .m文件中有@synthesize语句,请删除该语句)。另外,删除以下变量声明:id <UIScrollViewDelegate> delegate;

最后,作为旁注,当您遵守协议(如UIScrollViewDelegate)时,您不会声明您在* .h文件中实现的方法。因此,不需要Game类中的以下行:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView;
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;

希望这有帮助!