UIPickerView滚动行消失

时间:2018-02-20 05:19:34

标签: swift uipickerview

我已经搜索了但是我还没有找到解决方案,我有一个UIPickerView,当我开始查看工作正常时,当我滚动行消失时

class SemanaViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIPickerViewDataSource, UIPickerViewDelegate {

    let letters = ["A","B","C","D","F","G","H"]

    @IBOutlet weak var pickerView: UIPickerView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.pickerView.dataSource = self
        self.pickerView.delegate = self
        ....
    }
....
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return letters.count
    }


    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return letters[row]
    }

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

        let pickerLabel = UILabel()
        //pickerLabel.textColor = UIColor.red
        pickerLabel.text = letters[row]

        return pickerLabel
    }

打印

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

有什么建议吗?感谢

1 个答案:

答案 0 :(得分:0)

我发现错误是根据我创建视图的方式发生的。

我有一个UISegmentedControl和2个子视图(UIViewController),错误发生在1个子视图(SemanalmenteViewController),我已经改变了子视图创建这个工作的方式。

我不知道,但我认为这与父视图控制器有关。