Latest 0.2.1
Homepage https://github.com/allanalves/PickerFieldsDataHelper
License MIT
Platforms ios 8.0
Authors

PickerFields Data Helper

Swift (+3.0) Protocol to create Picker Views and Date Pickers to work with Text Fields’ outlets, providing selectable options to fulfill them.

Version
License
Platform

storyboard
storyboard

Usage

Just add the file ‘PickerFieldsDataHelper.swift’ to your project.

Delegation


class ViewController: UITableViewController, PickerFieldsDataHelperDelegate {

    let pickerFields = PickerFieldsDataHelper()

    override func viewDidLoad() {
        super.viewDidLoad()
        pickerFields.delegate = self
    }

}

Initializing


        //... (viewDidLoad method)

        //Setting up simple pickers with options for each text field
        pickerFields.addDataHelpers([accountTypeTextField, profileVisibilityTextField])

        //Setting up date Type field
        pickerFields.addDataHelper(birthDateTextField, isDateType: true)

Adding Data

You can add objects with representing titles to each field at any moment. Picker data are refreshed automatically.


    func loadAccountTypeOptions() {
        pickerFields.addTitleAndObjectInDataHelper(accountTypeTextField, title: "Normal User", object: 0)
        pickerFields.addTitleAndObjectInDataHelper(accountTypeTextField, title: "Admin", object: 1)
    }

    func loadProfileVisibilityOptions() {
        pickerFields.addTitleAndObjectInDataHelper(profileVisibilityTextField, title: "Private", object: "PRI")

        //Add an option to be default - starts with the option selected.
        pickerFields.addTitleAndObjectInDataHelper(profileVisibilityTextField, title: "Public", object: "PUB", isDefault: true)
    }

Getting Data

Use ‘selectedObjectForTextField’ method to get the current object for the selected option.

It can be nil if there is an non-value option selected like "Select an option".


    if let object = pickerFields.selectedObjectForTextField(accountTypeTextField) {
        //Use object
    } else {
        //No valid option selected
    }

Customization

Select Confirmation Button

        pickerFields.doneButtonTitle = "Choose"
        pickerFields.needsConfirmationButton = false //Selects without tapping the button

Non-value Default Option

        pickerFields.useDefaultFirstItem = true
        pickerFields.defaultFirstItemTitle = "Select an option"
        pickerFields.initWithDefaultFirstItemSelected = false //Start fields with "Select an option" text

Date Type: Start with today’s date

        pickerFields.initWithTodayDate = true

Clearing Fields

When calling ‘clearAllFields()’, all fields turn to default state.


    @IBAction func clearAllFields(sender: AnyObject) {
        pickerFields.clearAllFields()
    }

Optional Methods

Get title and object when selecting an item.


    func pickerFieldsDataHelper(dataHelper: PickerDataHelper, didSelectObject selectedObject: AnyObject?, withTitle title: String?) {
        //Use 'title' or 'selectedObject'.
    }

Cocoapods

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

PickerFieldsDataHelper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'PickerFieldsDataHelper'

Author

Allan Alves, [email protected]

License

PickerFieldsDataHelper is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "PickerFieldsDataHelper",
    "version": "0.2.1",
    "summary": "PickerFieldsDataHelper is a protocol in Swift, that helps using selectable options in text field outlets.",
    "description": "Swift (3) Protocol to create Picker Views and Date Pickers to work with Text Fields' outlets, providing selectable options to fulfill them.",
    "homepage": "https://github.com/allanalves/PickerFieldsDataHelper",
    "screenshots": [
        "https://raw.githubusercontent.com/allanalves/PickerFieldsDataHelper/master/Images/normal-picker.png",
        "https://raw.githubusercontent.com/allanalves/PickerFieldsDataHelper/master/Images/date-picker.png"
    ],
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Allan Alves": "[email protected]"
    },
    "source": {
        "git": "https://github.com/allanalves/PickerFieldsDataHelper.git",
        "tag": "0.2.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "PickerFieldsDataHelper/Classes/**/*",
    "pushed_with_swift_version": "+3.0"
}

Pin It on Pinterest

Share This