【问题标题】:Set up a pickerView from a asynchronous Json array从异步 Json 数组设置 pickerView
【发布时间】:2017-04-03 13:57:56
【问题描述】:

我有一个函数,getSemainesStages(),它读取一个远程 json 文件并将结果放入(全局范围)数组中。

问题是它是异步的,就像有人向我解释的那样,我需要这个数组来填充 pickerView 数据源。

所以当我打电话时:

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

数组还是空的,对于

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

只有在我的 getSemainesStages() 函数为空后,我才能做到这一点?

【问题讨论】:

标签: json swift swift3


【解决方案1】:

您可以在填充数组后调用UIPickerView.reloadAllComponents() 以重新加载部分/行:

var lesSemaines: [String] {
    didSet { 
        pickerView.reloadAllComponents()
    }
}

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 1970-01-01
    • 2017-11-02
    • 2019-04-08
    • 2014-08-28
    • 2013-05-09
    • 2017-02-12
    • 2020-08-07
    • 2014-02-25
    相关资源
    最近更新 更多