我是新手,现在我正尝试使用cocoapods在情节提要上创建一个下拉表。我遵循了cocoapods的所有教程,我猜这里的代码有问题。
请在这里给我一个启发,为什么在我声明下拉菜单的地方它不起作用。
谢谢您的帮助,感谢您。
import iOSDropDown
class ViewController: UIViewController {
@IBOutlet weak var DropDownMenu: DropDown!
let dropDown = DropDown()
let view = UIView()
dropDown.anchorView = view
dropDown.optionArray = ["option 1", "option 2", "option 3"]
最佳答案
override func viewDidLoad() {
super.viewDidLoad()
let dropDown = DropDown()
let view = UIView()
dropDown.anchorView = view // UIView or UIButton
// For set direction .top, .bottom or .any(for automatic)
dropDown.direction = .any
dropDown.optionArray = ["data 1", "data 2", "data 3"]
// for custom cell you can set xib
dropDown.cellNib = UINib(nibName: "MyCell", bundle: nil)
// select item from dropdown
dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
print("Selected item: \(item) at index: \(index)")
}
// if you want to set custom width then you can set.
dropDownLeft.width = 200
dropDown.show() // For Display Dropdown
dropDown.hide() // For hide Dropdown
}
有关更多详细信息和功能,请参考https://github.com/AssistoLab/DropDown