我有一个带有可变子视图的视图,子视图是使用描述此子视图类型的枚举设置的。我的问题是以下是否会导致强大的参考周期,或者是否有更好的方法来做到这一点:
class ControlBar: UIView {
var item = [ControlBarItemType : ControlBarItem]()
func set(with types: [ControlBarItemType]) {
for type in types {
let newItem = ControlBarItem(frame: CGRect(), type: type)
//constraints and stuff
self.addSubview(newItem)
item[type] = newItem
}
}
}
我不能将字典声明为弱。因此,超级视图将引用子视图层次结构中的每个 ControlBarItem 以及按类型索引的字典。我这样做的原因是有时我需要从充当 ControlBar 委托的 viewController 更改 BarItem 的状态。
