I have a problem to execute a function in a viewController from other viewController
I have two view controllers one called
ubicacionContainerViewController
and other
ReservaViewController
so I want to call a function in the reservaViewController from ubicacionContainerViewController
so in the ubicacionContainerViewController
I have this code:
let storyboard: UIStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
let reservaViewController: ReservaViewController =
storyboard.instantiateViewController(withIdentifier: "ReservaViewController") as!
ReservaViewController
reservaViewController.cambiarContainer()
I used the code above to call a function in ReservaViewController and all is ok it is called
but now in ReservaViewController
I have theses buttons
@IBOutlet weak var btnSelectUbicacion: UIButton!
@IBOutlet weak var btnSelectServicio: UIButton!
@IBOutlet weak var btnSelectHora: UIButton!
@IBOutlet weak var btnConfirmacionReserva: UIButton!
and this function:
func cambiarContainer() {
self.btnSelectUbicacion.setBackgroundImage(#imageLiteral(resourceName:
"fondo_transparente"), for: .normal) // here is the error
self.btnSelectServicio.setBackgroundImage(nil, for: .normal)
self.btnSelectHora.setBackgroundImage(#imageLiteral(resourceName:
"fondo_transparente"), for: .normal)
self.btnConfirmacionReserva.setBackgroundImage(#imageLiteral(resourceName:
"fondo_transparente"), for: .normal)
}
so the problem is when I press a button in ubicacionContainerViewController
to call appear that error.
I have tried using the "?"
func cambiarContainer(posicion: Int) {
self.btnSelectUbicacion?.setBackgroundImage(#imageLiteral(resourceName:
"fondo_transparente"), for: .normal) //no the error disapear
self.btnSelectServicio?.setBackgroundImage(nil, for: .normal)
self.btnSelectHora?.setBackgroundImage(#imageLiteral(resourceName:
"fondo_transparente"), for: .normal)
self.btnConfirmacionReserva?.setBackgroundImage(#imageLiteral(resourceName:
"fondo_transparente"), for: .normal)
}
now all is ok it works ok but the problem is that the background image of the buttons does not work . nothing change.