简体   繁体   English

如何在Swift中为核心数据保存uipickerview数据?

[英]How to save uipickerview data for core data in Swift?

There is one uipickerview in a single view application. 单视图应用程序中有一个uipickerview。 The user selects a name by click on a uibutton. 用户通过单击uibutton选择名称。

To be more specific 更加具体

  • there is one uibutton named as city 有一个名为城市的uibutton
  • the user clicks on the button and the uipickerview appears at the bottom and the user selects one name so the uipickerview disappears and the value is displayed in the uibutton named as city. 用户单击按钮,并且uipickerview出现在底部,并且用户选择了一个名称,因此uipickerview消失了,并且该值显示在名为city的uibutton中。

So, how to get the data from the uipickerview for coredata in iOS Swift application? 那么,如何在iOS Swift应用程序中从uipickerview获取coredata的数据呢?

You can set your class as picker view delegate throught delegate property on picker view. 您可以通过选择器视图上的委托属性将类设置为选择器视图委托。 Your class should conform to the UIPickerViewDelegate protocol, and implement method 您的类应符合UIPickerViewDelegate协议,并实现方法

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

you got row parametr here and you can just pick up the related data. 您在此处获得了row参数,您只需提取相关数据即可。 Then you can easily save it to core data. 然后,您可以轻松地将其保存到核心数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM