Я пишу xib
файл и файл swift для pickerView.Я хочу загрузить UIPickerView
в viewContainer UIViewController
.Я хочу показать сборщик, когда нажимаю на текстовое поле.Вы можете мне помочь?Спасибо
Это мой класс Swift:
import UIKit
class PickerView: UIView, UIPickerViewDelegate{
@IBOutlet var contentView: UIView!
@IBOutlet weak var picker: UIPickerView!
var pickerData : [String] = []{
didSet {
self.picker.reloadAllComponents()
}
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder : aDecoder)
commonInit()
}
private func commonInit(){
Bundle.main.loadNibNamed("Picker", owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
// The number of rows of data
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
// The data to return fopr the row and component (column) that's being passed in
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
print(pickerData[row])
return pickerData[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
// This method is triggered whenever the user makes a change to the picker selection.
// The parameter named row and component represents what was selected.
}
}