0
votes

I'm seriously losing my hair because of simple task which turned to hell. So I have UIScrollView subclass - MyScrollView and UIViewController subclass StoryViewController using that scroll view. I need to know when scroll is scrolled so what do I do? I try to delegate!

// StoryViewController.h
@interface StoryViewController : UIViewController <UIScrollViewDelegate>

// StoryViewController.m
// init
scrollView  = [[MyScrollView alloc] init];
scrollView.delegate = self;

// delegated function
- (void)scrollViewDidScroll:(UIScrollView *)s {
    NSLog(@"TEST");
}

Edit: Some NSLogs

Self: <StoryViewController: 0xfce090>
ScrollView Delegate: <StoryViewController: 0xfce090>
WebView Delegate: <StoryViewController: 0xfb1a30>

Edit:UIWebView subclass (MyWebView) which is subview of MyScrollView works fine and (void)webViewDidFinishLoad:(UIWebView*)webView (in the same storyviewcontroller.m) prints message.

No errors, builds fine, runs fine. After scrolling - nothing gets printed.

What am I doing wrong?

3

3 Answers

4
votes

This may be a red herring, but you're calling alloc and init, rather than alloc and initWithFrame:. I assume you're adding the scrollView in your viewDidLoad method? Is this a XIB-based controller? Have you tried adding the scrollview in the XIB file, and setting things up there? Have you tried adding other delegate methods?

3
votes

Are you sure that scrollView is in fact the scroll view that is displayed? A couple of things I can think of that I would check in order of desperation:

  1. Check that I actually added scrollView to self.view after self.view was loaded
  2. Check that when I add scrollView to self.view, it's the same object I had when I was assigning the delegate
  3. Checkwhen I add scrollView that scrollView's delegate is still set to the view controller
  4. Check that self is, in fact set to the view controller when assigning the delegate
  5. Try using a regular UIScrollView and see if anything changes
0
votes

So, once again, stupidity award goes to sniurkst. It was in fact UIWebView which was incorectly added to UIScrollView, so to me it was "oh my god, my scroll view is working", while it still was UIWebView scrolling on it's own.

Sorry, for my stupidity. Thank you all for trying to help me, next time I'll add more code samples, so you can see what's going on and laugh at my mistakes :)

And if someone would point me to an example how to correctly use ScrollView with WebView inside, so that ScrollView would be responsible for all the scrolling, I would be very thankful.