我正在尝试将数据从Objective-C ViewController传递到Swift ViewController,并且在我的Objective-C控制器中遇到此错误:
在“ UIViewController”类型的对象上找不到属性“ type”
我的Objective-C代码:
UIViewController *mainController = [self.storyboard instantiateViewControllerWithIdentifier:@"IdentitySelfieViewController"];
mainController.type = "passport";
[self.navigationController pushViewController:mainController animated:YES];
导入到桥接头文件中:
#import "PassportViewController.h"
并在我的Swift View Controller中创建了相应的String
let type = ""
感谢您的任何帮助
您的问题的解决方案是这样的:
首先在您的Swift Controller中@Objc
,在class关键字之前添加如下代码:
@objc class ViewController: UIViewController
然后在那个控制器中创建一个像这样的变量:
public var myValue:String = ""
之后,在Objective-C
ViewController中,您需要导入它,并记住这是非常重要的。
#import "TargetName-Swift.h"
TargetName应该替换为您的目标名称。之后,您可以像这样轻松地调用该Swift Controller的变量:
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
vc.myValue = @"Hello";
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句