【问题标题】:How to get the count of a Particular Subview in a UIView?如何获取 UIView 中特定子视图的计数?
【发布时间】:2016-03-20 12:29:46
【问题描述】:

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

【问题讨论】:

    标签: ios uitextview subviews


    【解决方案1】:

    斯威夫特 2:

    func numberOfTexViewInView(superView: UIView)-> Int{
    
            var count = 0
    
            for _view in superView.subviews{
    
                if (_view is UITextView){
                    count++
                }
    
            }
    
            return count
        }
    

    目标 C:

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

    将 UIExView 作为参数添加到函数中的主视图传递并获取结果。

    【讨论】:

      【解决方案2】:

      知道了!!!!

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

      【讨论】:

      • 但请注意,在您的示例中,文本视图必须是 self.viewdirect 子视图才能考虑!
      猜你喜欢
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多