Why can't I save the UIWebView UIcrollView delegate property anymore?

Prior to ios5, I was able to access the UIWebView UIScrollView delegate as follows:

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 this is not the right way to do this, but at the time (as I understand it) it was the only way to do this. iOS 5 changed this, so I'm trying to do it using iOS 5:

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

But in any case, I'm trying to do this, the value of my OldDelegate object is 0x0. It is very important that I keep this delegate value, but try as best as I can, I just get 0x0.

Any ideas?

I do not use ARC ...

+6
source share
2 answers

The scrollView property of the UIWebView is a subclass of UIScrollView . This private class, called _UIWebViewScrollView , does not use the delegate property, it is always zero. You can probably do the refactoring and get a real scrollview delegate, but I'm almost 100% sure that the apple will reject your application.

+1
source

Yes, if you use an arc, it is possible that it does garbage collection on your incomplete Olddelegate, you can either mark the file so that you do not use the arc with -fno-objc-arc, but handle the save and release yourself, as you used to. Or you can implement strong links as described here to help you keep the variable. https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html

0
source

Source: https://habr.com/ru/post/908800/


All Articles