How to view the subviews of a UIView within a UIView Objective-C

0

How can I see the components of a view within another view? As I see the components of the main view:

NSArray *sub = [self.view subviews];
if ([sub count] == 0) return;
for (int i=0; i<sub.count; i++){
  NSLog(@"Subview: %@", sub[i]);
}

And if you give me the components that have that view but what happens if that view has another view inside with other subviews as I can identify them, and try with:

NSArray *sub = [self.view subviews];
    if ([sub count] == 0) return;
    for (int i=0; i<sub.count; i++){

        if ([sub[i] isKindOfClass:[UIView class]]) {
            NSArray *sub1 = [sub[i] subviews];
            for (int x=0; x<sub1.count; x++){
                NSLog(@"ssssssss:::::::::::%@", sub1);
            }
        }
    }

But it is not that it does not work, but it recognizes the buttons as SUBVIEW and pulls the component that has inside let's say that if the button has an image it tells me that inside it has a UIImageview and if it has text a UIButtonLabel explain to me what is it what happens and how to get only the ones that UIView has at that moment, ONLY from the UIView.

    
asked by JCTimmypage 24.05.2017 в 00:47
source

1 answer

0

Well as always I am the only madman who always answers your questions. What happened, I discovered that the UIIbuttons function as a UIView in addition to UIButton because to store text or an image they work with a UIView generating a new subview either of type UIImageview or UIButtonlabel.

Apparently there is no way to avoid that so fix it with a simple condition.

NSArray *sub = [self.view subviews];
    if ([sub count] == 0) return;
    for (int i=0; i<sub.count; i++){

        if ([sub[i] isKindOfClass:[UIView class]] && [sub[i] isKindOfClass:[UIButton class]]) {
            // Un UIButton se reconoce igual como un UIView
        }
        else if ([sub[i] isKindOfClass:[UIView class]]){
            NSArray *sub1 = [sub[i] subviews];
            for (int x=0; x<sub1.count; x++){
                NSLog(@"ssssssss:::::::::::%@", sub1);
            }
        }
    }

The rest is explained alone.

    
answered by 24.05.2017 / 01:51
source