Reputation: 4253
I want navigate to another view controller that have a picker view, but this is generic, the content pickview must be selected according a type parameter passed before navigate. This parameter is a variable named tipo
So in my MainViewController I have a func to navigate:
@objc func handlerSelectOpTipo(_ sender: UILabel) {
let vcSelectTipo = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerSelect") as! ViewControllerSelect
// vcSelectTipo.tipo = .entrega // <- Example that I want.
vcSelectTipo.tipo = 0 // <- ENUM TYPE HERE
self.present(vcSelectTipo,animated: true,completion: nil)
}
Picker`s ViewController
class ViewControllerSelect : UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var pickerView: UIPickerView!
@IBOutlet weak var btOk: UIButton!
@IBOutlet weak var lblTitulo: UILabel!
var tipo : Int?
var conteudo : [String] = []
override func viewDidLoad() {
pickerView.setValue(UIColor.white, forKey: "textColor")
pickerView.dataSource = self
pickerView.delegate = self
btOk.addTarget(self, action: #selector(handlerBtOk), for: .touchUpInside)
}
@objc func handlerBtOk() {
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return conteudo.count
}
enum tipoConteudo: Int {
case tipo
case entrega
case priceList
case campanha
}
}
I can't access enum values of MainViewController for set var tipo : Int?
I wants some like:
vcSelectTipo.tipo = .entrega
vcSelectTipo.tipo = .priceList
but the autocomplete not show tipoConteudo
enum type.
Upvotes: 0
Views: 282
Reputation: 318944
You've declared the tipo
variable as an Int
instead of your enum type.
Change:
var tipo: Int?
to:
var tipo: TipoConteudo?
And type names should start with uppercase letters so tipoConteudo
should be TipoConteudo
.
Upvotes: 1
Reputation: 2432
All you need to do is change
var tipo: Int?
to
var tipo: tipoConteudo?
You just had the incorrect type for tipo.
Upvotes: 1