Daniel Ra Daniel Ra - 4 months ago 16
iOS Question

Trying to hide a button on another view, depending on segue chosen in swift xcode

Trying to hide a button on another view depending on the segue path chosen. So for example, if the "AddNewPokemon" segue is selected, then UIButton.hidden = true on the next view page.

if segue.identifier == "AddNewPokemon" {

let navigationController = segue.destinationViewController as! UINavigationController
let controller = navigationController.topViewController as! PokedexDetailsViewController

controller.cancelButtonDelegate = self
controller.delegate = self


I have tried browsing stackoverflow for the past hour, but to no avail, fairly new to swift.

https://d2vlcm61l7u1fs.cloudfront.net/media%2F4f4%2F4f4e42db-282d-46af-af14-6265be903c99%2FphpxgnWkQ.png

Answer
if segue.identifier == "AddNewPokemon" {
let navigationController = segue.destinationViewController as! UINavigationController
let controller = navigationController.topViewController as! PokedexDetailsViewController

//add line set the value created in PokedexDetailsViewController ie hideButton = true

controller.hideButton = true

controller.cancelButtonDelegate = self
controller.delegate = self

}

Create a var hideButton in PokedexDetailsViewController controller and set it true in prepare for segue and check in PokedexDetailsViewController viewdidload() method if true then hide it.

Hope this may help you.

Thanks

Comments