RaysonK
RaysonK

Reputation: 553

scrollViewDidScroll not getting called

I have a UIViewController that is a delegate of a UIScrollView called NumberLineScroll. I have set the delegate of the scrollview to be the view controller, but I am not getting any calls to scrollViewDidScroll: whenever the scrollview is scrolled. Here's the implementation:

The UIViewController header file (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;

and the component of the main file where the methods are implemented:

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

}

and here's the implementation of the UIScrollView (NumberLineScroll):

header file:

@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;

There's nothing that's very relevant in the main file. The only programming in there that I do to affect the scrolling is turn the bounce off and to switch the scrolling off when the ball is being moved by the user, then on again when they finish. Also, the locDelegate isn't a problem since that works just fine. The main problem is that NumberLineScroll is making no delegate calls. Why is this?

Also, the NumberLine view in NumberLineScroll is the contentview for the scrollview, just for clarification.

Upvotes: 1

Views: 3378

Answers (1)

LuisCien
LuisCien

Reputation: 6432

My best guess here is that you're redefining the delegate property inside you NumberLineScroll class. Try deleting the @property(nonatomic, assign)id <UIScrollViewDelegate> delegate; line (and if you have a @synthesize statement in your *.m file delete that one too). Also, delete the following variable declaration: id <UIScrollViewDelegate> delegate;.

Finally, just as a side comment, when you conform to a protocol (like UIScrollViewDelegate) you don't declare the methods that you implement in your *.h file. So, the following lines in your Game class are not needed:

- (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;

Hope this helps!

Upvotes: 3

Related Questions