ios - 多组件 UIPickerView 上的默认行
问题描述
该应用程序根据用户在 UIPickerView 上输入的当前里程表值来跟踪给定汽车的行驶距离。我已经能够构造它,有 6 个组件,行值范围从 0 到 9。如图所示:
当 PickerView 出现时,我希望它能够将最后跟踪的距离显示为选择的默认行。最后跟踪的距离存储在 Int 类型的 var (lastDistance) 中。
我能够根据 Int 的自定义扩展遍历距离上的每个数字。(lastDistance.digits:[Int])。还循环遍历每个组件。但不知道在 lastDistance 中为数字选择正确组件的正确方法。
组件数组始终为: components=[0, 1, 2, 3, 4, 5]
例如,如果值为 4400 英里。数字数组是 [4, 4, 0, 0],这个距离的正确选择应该是:
pickerView.selectRow(lastDistance.digits[0], inComponent: components[2], animated: false)
pickerView.selectRow(lastDistance.digits[1], inComponent: components[3], animated: false)
pickerView.selectRow(lastDistance.digits[2], inComponent: components[4], animated: false)
pickerView.selectRow(lastDistance.digits[3], inComponent: components[5], animated: false)
问题是当距离从 2 到 6 位变化时,选择的组件应该改变。
解决方案
推荐阅读
- php - 我的 HTML 表单应该由 PHP 页面处理,但显示的是 PHP 代码而不是执行
- r - 在 R 中,stringr:str_replace_all 不服从 'ignore_case = TRUE'
- angular - “UsersComponent”类型上不存在属性“可见性”
- flutter - Flutter 通过屏幕旋转改变 StaggeredGridView crossAxisCount
- r - 如何将 Wes Anderson 颜色添加到我的 GGPlot?
- visual-studio-code - vscode 获取对象属性到建议的顶部
- vim - vim 将 y,c,d 文本对象映射到寄存器中?
- kotlin - RxJava 使用第二个 observable 中的第一个 observable 的结果运行两个带有列表的 observables 作为结果
- html - 防止单击时关闭下拉菜单
- flutter - 包装小部件以提供选择多个用户时常见的堆叠效果