我制作了一个带有名为“AuthenticationViewController.h”的视图控制器和笔尖“AuthenticationViewController.xib”的框架。用于测试的示例项目用于展示 AuthenticationViewController。
在Objective-C
:
NSString *frameworkDirPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *frameworkBundlePath = [frameworkDirPath stringByAppendingPathComponent:@"xxx.framework"];
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
AuthenticationViewController *authenticationViewController = [[AuthenticationViewController alloc]initWithNibName:@"AuthenticationViewController" bundle:frameworkBundle];
authenticationViewController.delegate = self;
[self presentViewController:authenticationViewController animated:YES completion:nil];
这对我来说效果很好。
但是当我在中使用以下代码时Swift
:
let frameworkBundle = NSBundle(identifier: "xxx")
let authViewControler :AuthenticationViewController = AuthenticationViewController.init(nibName: "AuthenticationViewController", bundle: frameworkBundle)
authViewControler.delegate = self
self.presentViewController(authViewControler, animated: true, completion: nil)
该应用程序因错误而崩溃:-
由于未捕获的异常而终止应用程序
'NSInternalInconsistencyException',原因:'无法加载 NIB
捆绑包:'NSBundle
(已加载)' 名称为 'AuthenticationViewController''
NSBundle(identifier: "SendOTPFramework")
,Not NSBundle(path: <#T##String#>)
?您确定有可用的标识符吗?您在不同的语言中使用了不同的函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)