FirstViewController中的函数调用是-

@IBAction func redViewAct(sender :UIButton) {
        let nextview = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController1") as! ViewController1
        self.navigationController?.pushViewController(nextview, animated: true)
       let f1 = ViewController1()
        f1.view1Show()
    }

第二类方法-
@IBOutlet weak var redView: UIView!
    @IBOutlet weak var blackview: UIView!
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    func view1Show() {
        redView.hidden = false
        blackview.hidden = true
    }

最佳答案

像下面这样试试,FirstViewController,

@IBAction func redViewAct(sender :UIButton) {
    let nextview = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController1") as! ViewController1
    nextview.flag = "showView"
    self.navigationController?.pushViewController(nextview, animated: true)

}

在第二个视图中,
@IBOutlet weak var redView: UIView!
@IBOutlet weak var blackview: UIView!
var flag : String = ""

override func viewDidLoad() {
    super.viewDidLoad()

    if(self.flag == "showView")
    {
        redView.hidden = false
        blackview.hidden = true
    }
}

希望这对你有帮助。

08-18 07:31