Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I store a UIWebView's UIScrollView delegate property anymore?

Before ios5 I was able to access a UIWebView's UIScrollView delegate like this:

for (id subview in webView1.subviews){
    if ([[subview class] isSubclassOfClass: [UIScrollView class]])  {
        UIScrollView * s = (UIScrollView*)subview;
        OldDelegate = s.delegate;//OldDelegate is type id
                    s.delegate = self;
    }
}

Now, I know that's not the right way to do it, but at the time (as far as I understood) it was the only way to do it. iOS 5 has changed that, so I am trying to do it the iOS 5 way:

UIScrollView * s = webView.scrollView;
Olddelegate = s.delegate;
s.delegate = self;

But either way I try to do it, the value of my OldDelegate object is 0x0. It is really important that I retain this delegate value, but try as I might, I'm just getting 0x0.

Any ideas?

I'm not using ARC...

like image 529
Lizza Avatar asked Feb 18 '12 23:02

Lizza


1 Answers

The scrollView property of UIWebView is a subclass of UIScrollView. This private class, called _UIWebViewScrollView does not use the delegate property, it is always nil. Maybe you could do some refactoring and get the real scrollview-delegate, but i'm almost 100% sure apple will reject your app doing so.

like image 112
Jonathan Cichon Avatar answered Oct 02 '22 12:10

Jonathan Cichon