0

scrollView.bounces works properly on iOS 5 but when executed on iOS 4, sigabrt error is shown. How to set it working for both os? Thank you

- (void)viewDidLoad
{  
    [super viewDidLoad];

    [spinner startAnimating];
    [self.webView1 setDelegate:self];

    self.webView1.scrollView.bounces = NO;
    self.webViewB.scrollView.bounces = NO;

    [self loadIt];

}
Jaume
  • 3,672
  • 19
  • 60
  • 119

2 Answers2

1

Probably because web views in iOS 4 don't have a scrollView property - I think that arrived in iOS 5 :)

Look at the answer from Stop UIWebView from "bouncing" vertically? to fix it.

Community
  • 1
  • 1
deanWombourne
  • 38,189
  • 13
  • 98
  • 110
0

Your problem is not the setting the bounces property of the scrollView but rather trying to access the scrollView property of the webView1 and webViewB objects. Before iOS 5.0 this property was not public so you cannot access it like that.

You would have to go trough all the suviews of the webView1 and webViewB and find the one that's a UIScrollView and than set it's bouncing property. You can do that like this:

if ([self.webView1 respondsToSelector:@selector(scrollView)]) {
    self.webView1.scrollView.bounces = NO;
    self.webViewB.scrollView.bounces = NO;
}
else {
    for (UIView *subview in self.webView1.subviews) {
        if ([subview isKindOfClass:[UIScrollView class]]) {
            UIScrollView *scrollView = (UIScrollView *)subview;
            scrollView.bounces = NO;
        }
    }

    for (UIView *subview in self.webViewB.subviews) {
        if ([subview isKindOfClass:[UIScrollView class]]) {
            UIScrollView *scrollView = (UIScrollView *)subview;
            scrollView.bounces = NO;
        }
    }
}

Let me know if that works for you.

Mihai Fratu
  • 7,579
  • 2
  • 37
  • 63
  • 1
    I'd recommend putting this code into a category on `UIWebView` so you don't have to repeat it all through your apps :) – deanWombourne May 29 '12 at 21:31