我想知道是否有一条捷径可以让代码变得简单?
将“index”作为参数传递给我的onSectionSelected?
var index = 0
[view_a, view_b, view_c, view_d].forEach{
$0?.isUserInteractionEnabled = true
$0?.tag = index
index += 1
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(onSectionSelected))
$0?.addGestureRecognizer(tapGesture)
}
func onSectionSelected() {
//do something for touchUpInside event
}
强调我清楚地了解如何使用(索引,值)数组。列举来表达这一点。请相应地回答。