Search code examples
iosuitextviewsubviews

How to get the count of a Particular Subview in a UIView?


I want the count of a particular subview inside a UIView. I am adding some multiple textviews to my view and I want the count of the total UITextviews added to the view? I am able to iterate inside the subviews of the array but not able to find the exact count of the UITextViews. Any Idea?


Solution

  • Got it!!!!

    -(NSUInteger)getTotalNumberOfTextViewsAddedInTheView{
    
    NSUInteger count = 0;
    
    for (UIView *view in [self.view subviews]) {
    
        if ([view isKindOfClass:[UITextView class]]) {
    
            count ++;
        }
    }
    
    return count;
    }