I am writing a subclass of UIScrollView right now, and as part of what I am doing I need a second scrollView to contain all of the subviews.
The reason for this is that the second scrollview will have an 'actual' content size, while the subclass scrollview will have a larger content size, and in the -scrollViewDidScroll: I change the second scrollView's content offset based on the actual content offset.
When the user adds a subview to the scrollView, it will actually add it to the second scrollView.
One problem that I originally encountered was that the UIScrollView class adds two views to the scrollView (the scroll indicators) and I want to leave those be.
A workaround that I found, which is the top answer here (with modifications), that works for what I want is to get the name of the sender class in the -addSubview method like the following:
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
// Example: 1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
[array removeObject:@""];
if (![[array objectAtIndex:3] isEqualToString:@"<redacted>"]) {
//My code here
}
else {
[super addSubview:view];
}
Although this code block works and I am getting the results that I want, it seems kind of hacky, and requires checking if the calling class is "", which I would assume means that it doesn't want me to see its name. I am worried that using this method would cause problems if anything is changed in the future or if some other class has the value ""
Basically my question is (also TL;DR): Is there a better way (or more reliable) to check if the view being added (in -addSubview) is being added by the superclass (or even by self)?