keeping track of selections in Picker using Swift

Discussion in 'iOS Programming' started by theprizerevealed, Feb 11, 2017.

  1. theprizerevealed, Feb 11, 2017
    Last edited: Feb 11, 2017

    theprizerevealed macrumors member

    Feb 26, 2016
    I have several pickers in my app and I want to keep track of the selections of each picker before seguing to the next viewcontroller.

    Only after each picker has selected a satisfactory value do I want the current viewcontroller to segue to the next in the sequence.

    I tried to use an if statement that evaluates if all pickers have selected a satisfactory value before segueing however the Swift Compiler tells me that evaluating the conditional is too complex to complete in a reasonable time.

    I tried to use a simple counter but the Picker seems to trigger the counter when an acceptable value is passed or chosen temporarily but then an alternate value is chosen as the final choice. I cannot seem to make the counter in the Picker code recognize that a new alternate choice was selected and then reset the counter appropriately.

    Any helpful suggestions? thanks for your time.
    --- Post Merged, Feb 11, 2017 ---
    After tinkering with the pickerviews and removing all performsegue code then i was surprised to find that after all pickers have chosen a value (whether it is an acceptable value or not) then the viewcontroller segues to the next viewcontroller in sequence. Is that supposed to happen? Is that some feature of pickerview?
  2. Dookieman macrumors 6502

    Oct 12, 2009
    You should keep track of selected values via Bool, not a counter. If an appropriate value has been selected, set it's Bool = true. So create a Bool for each picker and check if all are true, proceed to the next view.

    Yes, all pickers have a default value, set to index[0] of it's data source. It's common to have [0] be empty or have information for what the picker means to the user. In the UIPickerController delegate, let [0] == false for your bools and anything over that == true.

Share This Page