【发布时间】:2016-04-10 03:58:05
【问题描述】:
我已经制作了一个框架,其中包含一个名为“AuthenticationViewController.h”的视图控制器,其 nib 为“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''
【问题讨论】:
标签: ios objective-c swift frameworks