I'm trying to mount a View that takes user data, such as height, weight, and age, using PickerViews.
There is no error returning, but when I execute, the pickerViews will only have one question, depending on the photo. In print, I am returning the correct number of [row], but not on the screen. Here is part of the code:
class IMCViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource
{
let arrayAnos : [Int] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
let arrayAltura: [Int] = [50, 51,52,53,54,55,56,57,58,59,60]
let arrayPeso: [Int] = [30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52]
override func viewDidLoad() {
super.viewDidLoad()
self.pickerViewPeso.delegate = self
self.pickerViewPeso.dataSource = self
self.pickerViewAltura.delegate = self
self.pickerViewAltura.dataSource = self
self.pickerViewIdade.delegate = self
self.pickerViewIdade.dataSource = self
// MARK: - Métodos de UIPickerViewDataSource
// Método que define a quantidade de components (colunas) do pickerView
func numberOfComponents(in pickerView: UIPickerView) -> Int {
if pickerView == pickerViewAltura {
// return arrayAltura.count
return 1
}
else if pickerView == pickerViewPeso {
return 1
} else {
return 1
}
}
// Método que define a quantidade de linhas para cada component
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView == pickerViewAltura
{
return self.arrayAltura.count
}
else if pickerView == pickerViewPeso
{
return self.arrayPeso.count
}
else
{
return self.arrayAnos.count
}
}
// MARK: - Métodos de UIPickerViewDelegate
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> Int! {
if pickerView == pickerViewPeso {
return self.arrayPeso[row]
}
if pickerView == pickerViewAltura {
return self.arrayAltura[row]
}
else{
return self.arrayAnos[row]
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView == pickerViewPeso {
print("Peso Selecionada: \(row)")
pesoUsuario = arrayPeso[row]
print ("O peso do usuário é: \(pesoUsuario)")
}
else if pickerView == pickerViewAltura {
print("Altura Selecionada: \(row)")
alturaUsuario = arrayAltura[row]
print ("Altura do usuário: \(alturaUsuario)")
}
else{
print("Idade Selecionada: \(row.description)")
idadeUsuario = arrayAnos[row]
print ("Idade do usuário:\(idadeUsuario)")
}
}
}