I have a UIView that has UILabels, UISliders, UITextboxes, etc. in it. I want to perform an action on just the sliders. How is this done? Currently, I have
int count = 0;
for (UIView *subview in [myView subviews])
{
if ([subview isKindOfClass:[UISlider class]]);
{
[subview removeFromSuperview];
NSLog(@"Class for object removed is %@",[subview class]);
count ++;
}
//else{do nothing - subview isn't a slider, so I don't care about it}
}
NSLog(@"count = %d",count);
When I run this code, everything is affected (sliders, as well as the labels, textboxes, and everything else). From what I gather from reading other posts, using isKindOfClass with arrays is kinda glitchy, but I thought that was only when trying to do isKindOfClass:[NSArray class]. Or am I wrong on that? If this nesting of isKindOfClass inside a for loop isn’t allowed, how do I perform actions on just certain items on my view?
EDIT: added whole code for one implementation of this. The count is off, and NSLog is telling me a whole bunch of UILabels are being removed. My view is completely emptied of everything after this runs.
EDIT 2: added ; at end of if statement like I have in my actual code. I removed it in my code and I now am getting the behavior I expected.
Turned out I had a typo. The
;at the end of my if statement was essentially making it like I didn’t have anifin there at all, which is why everything was being removed from my view. Removing the;made the code in my Question work as intended.