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

Asked

Viewed 70 times

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 are 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();
    }
}
  • You put it twice else if (row == 1). The second condition will never be executed.

2 answers

1

First you need to know which array wants to extract the value. If this is the case with the number array, use [1], which would be the second index of your pickerDataSource array. [Row] would be the index you want to extract from the array of numbers, according to your code so I used the Row.

To extract the value use this code:

pickerDataSource[1][row]

With this you have the value to perform the calculations.

  • Okay, what I’m trying to do is; If the value of the pickerDataSource(num) equals 1 and the value of the pickerDataSource(Letter) equals A. I open one background image, if different, open another. In the case of the example, I am changing the color only.

  • has how to put images of your code here, I have to know, to be able to answer. I wait.

  • I’m in class, I don’t have the file here. Coloco later. thanks!

  • Dude, I was able to solve it here. Then put the solution. It was worth the strength. .

0

if pickerDataSource[0][row] == "a" && pickerDataSource[1][row] == "1"{

    print ("coloque a cor desejada")

}
else{

    print ("coloque outra cor")

}

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.