OC和Swift互相跳转
2017-12-09 本文已影响43人
czj_warrior
首先在需要引入Swift的文件中导入头文件#import "工程名-Swift.h"
- OC跳转Swift页面:
#import "ViewController.h"
#import "OCAndSwift-Swift.h" // 引入头文件
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)btnClicked:(id)sender {
// Swift文件
ChildViewController *vc = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}
- Swift跳转OC页面:
首先创建Swift文件的时候回创建一个工程名-Bridging-Header.h
文件,在这个文件中将需要用到的OC文件导入到这里!!!
import UIKit
class ChildViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func btnClicked(_ sender: Any) {
let twoVC = ChildTwoViewController(nibName:"ChildTwoViewController", bundle: nil)
self.navigationController?.pushViewController(twoVC, animated: true)
}
哈哈,大功告成!!!
[图片上传失败...(image-b80a67-1512816958469)]