作者:谭禅心_136 | 来源:互联网 | 2023-09-16 09:42
我是新手,现在我正尝试使用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
,
import iOSDropDown
class ViewController: UIViewController,UITextFieldDelegate {
@IBOutlet weak var dropDown: DropDown!
override func viewDidLoad() {
super.viewDidLoad()
// The list of array to display. Can be changed dynamically
dropDown.optiOnArray= ["Option 1","Option 2","Option 3"]
//Its Id Values and its optional
dropDown.optiOnIds= [1,23,54,22]
// The the Closure returns Selected Index and String
dropDown.didSelect{(selectedText,index,id) in
print("Selected String: \(selectedText) \n index: \(index)")
self.dropDown.hideList()
self.dropDown.text = selectedText
}
}
}
func textFieldDidBeginEditing(_ textField: UITextField) {
dropDown.showList()
}
}
您可以引用此链接https://cocoapods.org/pods/iOSDropDown
,
在viewDidLoad
中写入初始化代码:
override func viewDidLoad() {
super.viewDidLoad()
let dropDown = DropDown()
let view = UIView()
dropDown.anchorView = view
dropDown.optiOnArray= ["option 1","option 2","option 3"]
}