阵列数据在选择器视图上不可见

时间:2019-07-10 06:23:37

标签: swift uipickerview

我有要显示在UIPickerView上的数组数据,但是数据没有显示在选择器视图上。我的代码:

@IBOutlet var txt: UITextField!
let PickerView = UIPickerView()
override func viewDidLoad() {
  super.viewDidLoad()
        Json()
        txt.inputView = PickerView
        PickerView.delegate = self
        PickerView.dataSource = self
        // Do any additional setup after loading the view.
    }
   func Json()
    {
      { (response, error) in
            if response != nil
            {

                let Value = response!["data"] as! [[String:Any]]
                for dic in dataDict
                {

                    if let job = dic["Jobs"] as? String
                    {
                        print(job)
                        self.array.append(job)
                        print(self.array)
                    }

                }

            }

        }
    }
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return array.count
    }
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        txt.text = array[row]
    }
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return array[row]
    }

为什么会这样,有什么办法可以解决这个问题?

1 个答案:

答案 0 :(得分:0)

    txt.inputView = PickerView
    PickerView.delegate = self
    PickerView.dataSource = self
    Json()

请重新加载picker.reloadAllComponent()