Picker View - Display an ImageView according to the sum of values

0

Hello.

I'm trying to work with Picker View to display a combination of values.

 var pickerDataSource = [["a", "b", "c", "d"],["1","2","3","4"]];

Doubt is; how do I get results within a condition?

        if(row == 0)
    {
        self.view.backgroundColor = UIColor.whiteColor();
    }
    else
        if(row == 1)

    {
        self.view.backgroundColor = UIColor.redColor();
    }
    else if(row == 1)
    {
        self.view.backgroundColor =  UIColor.greenColor();
    }
    else if(row == 3)
    {
        self.view.backgroundColor =  UIColor.blueColor();
    }
    else
    {
        self.view.backgroundColor = UIColor.blueColor();
    }
}
    
asked by anonymous 28.03.2016 / 22:55

2 answers

1

First you have to know which array you want to extract the value from. If this is the case for the array of numbers, use [1], which would be the second index of your pickerDataSource array. The [row] would be the index you want to extract from the array of numbers, depending on your code so I used row .

To extract the value use this code:

pickerDataSource[1][row]

With this you have the value to perform the calculations.

    
29.03.2016 / 23:18
0
if pickerDataSource[0][row] == "a" && pickerDataSource[1][row] == "1"{

    print ("coloque a cor desejada")

}
else{

    print ("coloque outra cor")

}

Before the else, you can put an else if and go putting other possibilities of values and colors for the result.     

01.04.2016 / 19:32