Hello,
For example, I have a view, on that view there is a scrollview.
Is it possible to know, when any subview has been added on that scrollview without subclassing the UIScrollView and overriding the method didAddSubview:
?
Basically, is it possible to receive notifications when the number of subviews has been changed?
Thanks.
Asked
Active
Viewed 1,090 times
1

0xDE4E15B
- 1,284
- 1
- 11
- 25
-
Why don't you want to subclass the scroll view? – omz Aug 28 '12 at 21:33
-
@omz just curious. Wanted to find something new. – 0xDE4E15B Aug 28 '12 at 21:35
-
Wonder if you could swizzle UIView's implementation of `didAddSubview:` to emit some sort of notification; but this would rely on all UIView subclasses calling the superclass implementation in their own, which is unlikely :( – Carl Veazey Aug 28 '12 at 21:52
-
1Method swizzling could work, but it seems that Apple [doesn't want that in the App Store](http://stackoverflow.com/a/7722169/573626). I think the fact that there is a `didAddSubview:` method that is meant to be overridden in subclasses, indicates that there is no other (good) way to achieve the same thing. If there was a notification mechanism or if it was KVO-compliant, there would be no need for that method... – omz Aug 29 '12 at 00:46
-
I did not know Apple was doing away with swizzling. Just dreadful :) But you're right it probably would have caused more issues than it solved. – Carl Veazey Aug 29 '12 at 06:20