swift - Change a button's characteristic outside class programatically -


in code below, want able change visibility of button in class, when try change button.ishidden false, button still doesn't show up.

view controller 1:

override viewdidload(){      button.ishidden = true } 

view controller 2:

viewcontroller1().button.ishidden = false 

how can change button's visibility controller

calling viewcontroller1() creates viewcontroller1 instance instead of working viewcontroller1 instance has been instantiated.

to access properties (in case button) of viewcontroller1 viewcontroller2, have pass reference button viewcontroller1 viewcontroller2 , change properties through reference.

you need set reference in prepare(for segue) function in viewcontroller1.

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if segue.identifier == "mysegue {         let nextvc = segue.destination as! viewcontroller2         nextvc.button = sender as! uibutton     } } 

you need set segue manual , call in viewcontroller1 self.performsegue(withidentifier: "mysegue", sender: self.button)

you need create property in viewcontroller2 , access this:

class viewcontroller2 {    var button:uibutton?     func showbuttononvc1(){        guard let button = self.button else { return }        button.ishidden = false    }  } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -