代码之家  ›  专栏  ›  技术社区  ›  Austin Berenyi

为什么在prepareForSegue中“实例成员”不能用于类型“uuuuuuuu”?

  •  1
  • Austin Berenyi  · 技术社区  · 7 年前

    我尝试使用此方法将数据从一个视图控制器传递到另一个视图控制器:

    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    
            if segue.identifier == "toSecondViewController" {
                let secondViewController = segue.destination as! SecondViewController
    
                SecondViewController.username = "Austin"
            }
    
        }
    

    实例成员“username”不能用于类型 “SecondViewController”

    变量 username SecondViewController 而segue确实被命名为 toSecondViewController

    1 回复  |  直到 7 年前
        1
  •  1
  •   Martin Muldoon    7 年前

    if segue.identifier == "toSecondViewController" {
                let secondViewController = segue.destination as! SecondViewController
    
                SecondViewController.username = "Austin"
            }
    

    注意如何 SecondViewController.username = "Austin" 大写S。。它应该是小写的。

    let secondViewController as! SecondViewController 但是你试着去设定。SecondViewController上的用户名,大写S

    你应该设置。变量上的用户名 secondViewController . 小写s,这是您想要的。