YogevSitton
YogevSitton

Reputation: 10108

self.view.subviews not showing buttons

I want to iterate through all of the subviews in my view, and do something for each UIButton. This is the code i'm using (in the end of the viewDidLoad):

for(UIView* v in self.view.subviews)
{
    if([v isKindOfClass:[UIButton class]])
    {
        NSLog(@"This is a button");
        //DO SOMETHING FOR EACH BUTTOn
    }
}

But the problem is that the "This is a button" line is never reached...

Why is that?

Upvotes: 0

Views: 334

Answers (2)

Charles D'Monte
Charles D'Monte

Reputation: 372

for (UIButton *eachButton in self.view.subviews)
{     
     [eachButton methodWhichYouNeedToAssign];
}

Hope this helps :-)

Upvotes: 1

Lithu T.V
Lithu T.V

Reputation: 20021

self.view.subviews will return only the subviews of that view.

For eg. View A->View B ->view C

Subviews of View A will list only View B,View C will be only available as the subview of view B

So try some recursive method to drilldown into all the subviews

Upvotes: 0

Related Questions