Return 个项目位于多个数组中的同一位置

Return items at the same location in multiple arrays

我正在创建一个小型参考应用程序,它使用 UIPicker 来 select 一个组织,然后显示基于 selection 的信息。基本格式为:

这里是选择器

"Here is the info for (selected organisation)"

信息 1:(此处来自信息 1 数组的信息)

信息 2:(此处来自信息 2 数组的信息)

信息 3:(此处来自信息 3 数组的信息)

信息 4:(此处来自信息 4 数组的信息)

信息 5:(此处来自信息 5 数组的信息)

我已经完成了选择器的编码,它正在 return 从供给它的数组中提取 selected 组织的值。

其他数据包含在单独的数组中,但信息的位置在所有数组中都是一致的。位置 0 的组织将在其他数组中的位置 0 包含其所有详细信息。

我想要做的是 return 来自其他数组的值,这些值与选择器 return 的结果位于同一位置。这样,每次移动选择器时,屏幕上的数据都会更新。

我找不到引用我的选择器return结果的位置并使用它来访问我需要显示的其他信息。

如果有任何关于如何管理这些数据的其他建议...

有什么想法吗?

您需要为您的UIPickerView定义一个委托。

class Controller:UIViewController, UIPickerViewDelegate {

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

        print("User selected row \(row)")
    }
}

Don't forget to wire the delegate property of the Picker view to your ViewController in Interface Builder.

现在每次用户select一个值,上面的方法都会被调用。您只需要使用 row 参数来访问您的数组。