将swift类导入到客观c故事板中

时间:2015-04-25 20:55:06

标签: ios objective-c swift storyboard interface-builder

我试图将项目https://github.com/ariok/BWWalkthrough实施到我的目标c项目中。

我有一个Xcode自动为我制作的objc桥接标题

我将ViewController.swift代码翻译为

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Walkthrough" bundle:nil];
BWWalkthroughViewController *walkthrough = [sb instantiateViewControllerWithIdentifier:@"walk"];
BWWalkthroughPageViewController *page_zero = [sb instantiateViewControllerWithIdentifier:@"walk0"];
BWWalkthroughPageViewController *page_one = [sb instantiateViewControllerWithIdentifier:@"walk1"];
BWWalkthroughPageViewController *page_two = [sb instantiateViewControllerWithIdentifier:@"walk2"];
BWWalkthroughPageViewController *page_three = [sb instantiateViewControllerWithIdentifier:@"walk3"];

walkthrough.delegate = self;
[walkthrough addViewController:page_zero];
[walkthrough addViewController:page_one];
[walkthrough addViewController:page_two];
[walkthrough addViewController:page_three];

[self presentViewController:walkthrough animated:YES completion:nil];

我像这样导入swift类:

import“SkipTheLine-Swift.h”

我的桥接头文件的名称是“SkipTheLine-Bridging-Header.h”

现在,当我运行代码时,我得到了这个

2015-04-25 16:47:46.740 SkipTheLine [1631:215786] Interface Builder文件中的未知类BWWalkthroughViewController。 2015-04-25 16:47:46.754 SkipTheLine [1631:215786] - [UIViewController setDelegate:]:无法识别的选择器发送到实例0x12651cf90 2015-04-25 16:47:46.755 SkipTheLine [1631:215786] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UIViewController setDelegate:]:无法识别的选择器发送到实例0x12651cf90' * 第一次抛出调用堆栈: (0x1838aa530 0x19482c0e4 0x1838b15f4 0x1838ae3ac 0x1837b2c4c 0x10009c494 0x1880eca14 0x1880d5d08 0x1880ec3b0 0x1880ec03c 0x1880e5590 0x1880b8e60 0x18835846c 0x1880b73d0 0x183862d34 0x183861fd8 0x183860088 0x18378d1f4 0x18cbb76fc 0x18811e10c 0x10009e174 0x194eaaa08) libc ++ abi.dylib:以NSException类型的未捕获异常终止

关于如何在界面构建器中使用swift代码的任何想法?

1 个答案:

答案 0 :(得分:2)

想出来了!

您只需要在界面构建器中将MODULE编辑为项目名称!!