简体   繁体   English

Swift 3-实例化视图控制器后无成员错误

[英]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.

相关问题 在Swift中使用标识符实例化视图控制器 - Instantiating a view controller with identifier in Swift Swift 2预期的声明错误和实例成员不能在视图控制器上使用 - Swift 2 Expected Declaration error & instance member cannot be used on view controller 实例化视图 controller 时出现 TypeMismatch 错误 - TypeMismatch error when instantiating view controller Swift-以编程方式实例化视图控制器时缺少元素 - Swift - Elements missing when programmatically instantiating a view controller 从情节提要实例化后无法分配给视图控制器的属性 - Cannot assign to view controller's property after instantiating from storyboard Swift-实例化新视图控制器时如何保持对旧视图控制器的引用? - Swift - How to keep reference to old view controller when instantiating new view controller? Swift-无法从子视图控制器调用公共功能? ViewController没有成员错误? - Swift - can't call public function from child view controller? ViewController has no member error? 哪个View Controller实例化Destination View Controller? - Which View Controller is instantiating the Destination View Controller? Swift 2:实例成员不能在“ View Controller”类型上使用 - Swift 2: Instance Member cannot be used on type “View Controller” Swift 3:实例成员不能在“ View Controller”类型上使用 - Swift 3: Instance Member cannot be used on type “View Controller”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM