Я новичок в разработке для iOS.Пожалуйста, проверьте код ниже.
let dropDown = DropDown()
override func viewDidLoad() {
super.viewDidLoad()
dropDown.anchorView = dropDownTest // UIView or UIBarButtonItem
dropDown.dataSource = ["Car", "Motorcycle", "Truck"]
dropDown.bottomOffset = CGPoint(x: 0, y:(dropDown.anchorView?.plainView.bounds.height)!)
dropDownTest.addTarget(self, action: #selector(self.buttonClicked(sender:)), for: .touchUpInside)
}
@objc private func buttonClicked(sender: UIButton) {
dropDown.show()
}
Это было довольно легко, потому что переменная dropDown
может быть вызвана из метода buttonClicked
.Но, в моем случае, я должен сделать это внутри метода, связанного с ячейками таблицы cellForRowAt
.
let cell = tableView.dequeueReusableCell(withIdentifier: "VarientCell", for: indexPath)
let varientButtonTag = 1
let varientButton = cell.viewWithTag(varientButtonTag) as! UIButton
let varientDropDown = DropDown()
varientDropDown.anchorView = varientButton
varientDropDown.dataSource = datasource
varientDropDown.bottomOffset = CGPoint(x: 0, y: varientButton.bounds.height)
varientButton.addTarget(self, action: #selector(self.varientButtonClicked(sender:)), for: .touchUpInside)
return cell
и метод нажатия кнопки,
@objc private func varientButtonClicked(sender: UIButton) {
//dropDown.show()
// my problem is here.., i need to pass the dropDown somehow to show that.
}