尝试隐藏另一个视图上的按钮,具体取决于在swift xcode中选择的segue

时间:2016-07-24 02:59:01

标签: ios swift xcode

尝试根据所选的segue路径隐藏另一个视图上的按钮。例如,如果" AddNewPokemon"选择segue,然后在下一个视图页面上显示UIButton.hidden = true。

if segue.identifier == "AddNewPokemon" {

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

    controller.cancelButtonDelegate = self
    controller.delegate = self

我曾尝试过去一小时浏览stackoverflow,但无济于事,相当新的swift。

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

1 个答案:

答案 0 :(得分:0)

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

}

在PokedexDetailsViewController控制器中创建一个var hideButton并将其设置为true以准备segue并检查PokedexDetailsViewController viewdidload()方法如果为true则隐藏它。

希望这可以帮助你。

由于