如何将Integer而不是UIpickerView中的字符串保存到数据库?

时间:2019-02-28 14:01:14

标签: ios swift xcode uipickerview

我正在使用UIpickerview将值保存到数据库, 但是我想保存Integer而不是string并保留string以仅显示给用户

this my code

更多说明: 如果用户选择麦加我要在数据库中保存1,如果选择开罗将2保存到数据库中

1 个答案:

答案 0 :(得分:0)

您可以尝试使用row委托方法整数,并在索引从0开始时将其加1。

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    let stored = row + 1   
    print(stored)
}