ios - 在选取器视图中显示字符串数组?
问题描述
如何在不使用 didSelect 委托方法的情况下在选择器视图中显示字符串数组?
解决方案
func numberOfComponents(in pickerView: UIPickerView) -> Int
{
return 1 // the amount of "columns" in the picker view
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return yourArray.count // the amount of elements (row)
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
return yourArray[row] // the actual string to display for the row "row"
}
就那么简单。不需要 didSelect。每当您在选择器视图中更改您的选择时,就会调用 didSelect 委托函数。你不需要那个来显示数据
推荐阅读
- list - 如何在 SAPUI 中禁用 ListItem
- json - 我在 Swift 5 上解码 json 时出错
- php - 你如何销毁 2 行,laravel 中的每个表中的一个?
- android - Kotlin 编译器优化?
- python - Pyqt5如何每5分钟运行一次脚本或运行脚本以检查网络中的线程
- react-native - 如何找出在本机反应中可见的flatlist最后一项
- spring - 在分布式环境中获取访问令牌
- javascript - Nuxtjs 抛出“不要在突变处理程序之外改变 vuex 存储状态”
- kotlin - 无法编译颤振应用程序 - Kotlin 相关错误
- ngrx - Effect 调度了一个无效的动作 - 动作必须是对象