简体   繁体   中英

How to best convert a textfield to a picker

I am working on an application which has several textfields and a single UIImage. I would like to now enhance it to use an UIPicker so that the user does not have to type it in. This would be for things like color, size, type, etc.

The data I need to fill the UIPickers with is static (strings).

My question is centered around whether there is an easy way to change the type, from textfield to UIPicker, using something like Refactor and have xCode do the rest for me.

Also, how do I go about getting the value selected once the user has selected it and selected the "Save" button.

How about when I retrieve the data during an UPDATE operation? How can I have the application "default" to the UIPicker value previously selected.

The application uses Core Data to store data.

Thanks in advance. Anye

In a word, no.

You need to write code that manages the picker view. You have to set up a data source and a delegate, and write the methods that manage the messages in the data source and delegate protocols. It's fairly simple but there are a number of steps involved.

Since you have several fields you want to replace with pickers you would write your data source and delegate methods to look at the picker view that's passed to the data source/delegate methods and handle each one appropriately.

Picker views have methods that let you either set the selected row or query the selected row.

I suggest you search on "UIPickerView" in the Xcode docs and read the entire class reference, as well as the sections on the UIPickerViewDelegate and UIPickerViewDataSource protocols.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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