Я хочу использовать несколько выпадающих.Но возникает ошибка «Индекс вне диапазона»
var drop: Array<DropDown?> = []
var dropDataSource: Array<String> = []
@IBOutlet var buttons: [UIButton]!
Я объявил вот так.
func setDropDown() {
for i in 0...15 {
drop[i] = DropDown()
drop[i]?.anchorView = button
drop[i]?.bottomOffset = CGPoint(x: 0, y:(dropDown?.anchorView?.plainView.bounds.height)!)
switchDropData(dataCount: i)
drop[i]?.dataSource = dropDataSource
buttons[i].addTarget(self, action: #selector(dropBtn), for: .touchUpInside)
drop[i]?.selectionAction = { [unowned self] (index: Int, item: String) in
self.buttons[i].setTitle(item, for: .normal)
}
}
}
@objc func dropBtn(dataCount: Int) {
drop[dataCount]?.show()
}
и сделаю 15 выпадений.
, но drop[I] = DropDown()
приводит кошибка.
Я знаю, что означает «Ошибка индекса вне диапазона».
Но я не знаю, почему в этом коде есть ошибка.
Есть что-нибудь, япропал в коде?