Jquery 在Swift中查询子视图

Jquery 在Swift中查询子视图,jquery,ios,arrays,uikit,swift2,Jquery,Ios,Arrays,Uikit,Swift2,我遇到问题的代码行是 if let buttons = self.viewWithTag(7) as! Button { buttons.backgroundColor = UIColor.MDColor.white buttons.title?.textColor = UIColor.MDColor.grey800 } 在前面的代码中,我将42个对象的数组设置为标记为7。稍后在一个函数中,我将尝试获取所有这些对象并更改一些属性。我遇到的问题是代码没有查询所有42个视图,我不知

我遇到问题的代码行是

if let buttons = self.viewWithTag(7) as! Button {
    buttons.backgroundColor = UIColor.MDColor.white
    buttons.title?.textColor = UIColor.MDColor.grey800
}
在前面的代码中,我将42个对象的数组设置为标记为7。稍后在一个函数中,我将尝试获取所有这些对象并更改一些属性。我遇到的问题是代码没有查询所有42个视图,我不知道是否有任何视图被更改。我也试过了

if let buttons = self.viewWithTag(7) as? Button {
        if buttons.backgroundColor == self.accentColor {
            buttons.backgroundColor = UIColor.MDColor.white
            buttons.title?.textColor = UIColor.MDColor.grey800
        }

    }

我认为self中按钮的
类似于
循环可以工作,但编译器返回的
日期选择器
不符合协议
序列类型
。我是否应该将
SequenceType
添加到类中?

如果您查看文档,您将看到
func viewWithTag(u-tag:Int)->UIView?
返回一个带有标记的视图,而不是所有视图。如果您从情节提要加载视图或仅从视图数组加载视图,我将创建
IBOutletCollection
,如下所示:

@IBOutlet var buttons: [Button]! // for IBOutlet collection
// or
var buttons: [Button]!
然后,您只需要遍历数组:

for button in buttons {
    if button.backgroundColor == self.accentColor {
        button.backgroundColor = UIColor.MDColor.white
        button.title?.textColor = UIColor.MDColor.grey800
    }
}

我发现答案是肯定的

let view = self.dialog?.subviews.filter({$0.tag == 1})
向下俯冲一层,我想改变的是向下两层

要想得到我想要的风景,我很高兴

for button in view![0].subviews.filter({$0.tag == 7}) {
      let buttons = button as! Button
      buttons.backgroundColor = UIColor.MDColor.white
      buttons.title?.textColor = UIColor.MDColor.grey800
}

这不起作用,UIView仍然没有序列类型。要迭代视图,我需要使用self.subviews之类的东西。然后可能会提供一个代码,说明您使用said
DatePicker
试图实现什么
UIView
不是序列类型,但是
UIView
数组是
CollectionType
类型,它是
SequenceType
…是的,我在self.subview中为视图添加了for循环,但仍然丢失了。