注意: 这不是任何问题的重复。我无法找到任何一个问题,其中包含一些操作方法并创建了一个基于Swift的视图控制器实例。
我在Objective-C类的.m文件中调用了一个基于Swift的视图控制器。
在我的ViewController.m
中,我已经导入了桥接头文件。
#import "ViewController.h"
#import "Project-Bridging-Header.h"
我想从下面的操作中调用基于Swift的视图控制器。
- (IBAction)tappedButnGo:(UIButton *)sender {
SwiftViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SwiftViewController"];
}
我这里遇到了一个错误
未声明的标识符 SwiftViewController 的使用
下面是 Swift 类的代码:
import UIKit
@objc class SwiftViewController: UIViewController {
//so on
我的BridgingHeader
是空的。
当我点击Objective C
的按钮动作时,有人能帮我加载SwiftViewController
吗?
#import "AutoLayout-Swift.h"
,AutoLayout 是我的项目名称。 - SantoViewController.m
中导入它,这是Obj-c类。 - Santo#import "X_Ample.h"
,如果还不行,那么你可以在Build Setting
中搜索Objective-C Generated Interface Header Name
,找到运行时生成的Swift.h
文件名,并使用它。参考此图片。 - Nirav D