[英]Swift 3 - No member error after instantiating view controller
I am using Swift 3, Xcode 8.2. 我正在使用Swift 3,Xcode 8.2。
When I instantiate a view controller and try to access one of its variables, I get a: Value of type 'UIViewController' has no member 'someObjectVar'
当我实例化视图控制器并尝试访问其变量之一时,我得到: Value of type 'UIViewController' has no member 'someObjectVar'
Here is my code: 这是我的代码:
let testVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "testVC") as UIViewController
testVC.someObjectVar = someObject // error is here
self.present(testVC, animated: true, completion: nil)
The variable in testVC
is: testVC
的变量是:
var someObjectVar : someObjectType!
I found this question which has the same issue as me but the solution doesn't work for me since I am not doing the same thing... 我发现这个问题与我有相同的问题,但是解决方案对我不起作用,因为我没有做同样的事情...
Any help would be greatly appreciated. 任何帮助将不胜感激。
You are casting it to UIViewController which most definitely does not have that property on it. 您正在将其投射到UIViewController上,后者绝对不具有该属性。 You need to cast it as whatever UIViewController subclass you made that has that property associated with it. 您需要将其强制转换为具有该属性关联的任何UIViewController子类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.