如何获取 UIView 中特定子视图的计数?

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

我想要 UIView 中特定子视图的计数。我正在向我的视图中添加一些多个文本视图,并且我想要添加到视图中的 UITextviews 总数?我能够在数组的子视图中进行迭代,但无法找到 UITextViews 的确切计数。有什么想法吗?

知道了!!!!

-(NSUInteger)getTotalNumberOfTextViewsAddedInTheView{

NSUInteger count = 0;

for (UIView *view in [self.view subviews]) {

    if ([view isKindOfClass:[UITextView class]]) {

        count ++;
    }
}

return count;
}

Swift 2:

func numberOfTexViewInView(superView: UIView)-> Int{

        var count = 0

        for _view in superView.subviews{

            if (_view is UITextView){
                count++
            }

        }

        return count
    }

Objective C:

-(NSUInteger)numberOfTexViewInView:(UIView *)superView{

    NSUInteger count = 0;

    for (UIView *view in superView.subviews) {
        if ([view isKindOfClass:[UITextView class]]) {
            count ++;
        }
    }

    return count;

}

传递您的主视图,其中您的 UITexView 作为参数添加到该函数并获得结果。