无法从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。
- 具有非矩形边界的UIDynamicItem
- 将对象从NSMutableDictionary添加到NSMutableArray
- 如何使用swift在UICollectionView单元格中加载自定义单元格(xib)
- 我的自定义UIView dos不接收触摸
- 如何在NSUserDefaults中使用存储和使用NSMutableAttributedString
- 如何更改MFMessageComposeViewController元素的颜色?
- 执行SegueWithIdentifier和viewDidLoad
- 如何使用AVFoundation为您的video添加不同的图像和不同的CMTime
- 使用Swift-NIO开发基本的Swift Echo Server