1

我有一个被调用UIViewController的代表。我已将滚动视图的委托设置为视图控制器,但每当滚动视图滚动时,我都没有收到任何调用。这是实现:UIScrollViewNumberLineScrollscrollViewDidScroll:

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
...

}

这是UIScrollViewNumberLineScroll)的实现:

头文件:

@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视图NumberLineScroll是滚动视图的内容视图,仅用于说明。

4

1 回答 1

3

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

希望这可以帮助!

于 2013-07-10T00:00:15.090 回答