无法从iOS中的框架访问.nib(XIB)文件

我已经创build了一个我现有的代码库的框架,并试图在一个新的代码库中使用它。 这工作得很好。 但是当我尝试访问作为我的框架包的一部分的nib文件时,我的应用程序崩溃了。 这是我用来访问视图控制器XIB文件的代码。

testViewController *controller = [[testViewController alloc] initWithNibName:@"testViewController" bundle:nil]; [self.view addSubview:controller.view];

该应用程序崩溃而不会产生任何错误或崩溃报告。 这里是我的问题

1 – 我们可以在我们的框架中添加xib文件吗?

2 – 如果是,从framawork中添加和访问nib(xib)文件的正确方法是什么 (目前我已经将它们添加到“ 构build设置 ”的“ 构build阶段 ”选项卡的“ 编译源代码 ”部分中)

你需要写出你笔尖的包的名字。 文件是商店,所以改变你的上面的代码…

 testViewController *controller = [[testViewController alloc] initWithNibName:@"testViewController" bundle:yourBundle]; [self.view addSubview:controller.view]; 

这里你的bundle是一个NSBundletypes的对象。 请参阅NSBundle类获取更多信息

在迅速2 – 对于故事板:

 let bundle = NSBundle(identifier:"com.bundileName.Name") let storyboard = UIStoryboard(name:"Storyboard", bundle:bundle!) let controller = storyboard.instantiateViewControllerWithIdentifier("ViewControllerId") as UIViewController presentViewController(controller, animated: true, completion: nil) 

对于XIB:

 let bundle = NSBundle(identifier:"com.bundileName.Name") if !(bundle == nil){ let objtestViewController = testViewController(nibName: "testViewController", bundle: bundle) presentViewController(objtestViewController, animated: true, completion: nil) } 

Swift 3 Storyboard:

  let bundle = Bundle(identifier:"com.bundileName.Name") let storyboard = UIStoryboard(name:"Storyboard", bundle:bundle!) let controller = storyboard.instantiateViewController(withIdentifier: "ViewControllerId") as UIViewController present(controller, animated: true, completion: nil) 

厦门国际银行

 let bundle = NSBundle(identifier:"com.bundileName.Name") if !(bundle == nil){ let objtestViewController = testViewController(nibName: "testViewController", bundle: bundle) present(objtestViewController, animated: true, completion: nil) } 

这里的bundle name是framework的bundle id。