xcode 加载框架中包含的笔尖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12557936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:35:56  来源:igfitidea点击:

Loading a nib that's included in a Framework

objective-ciosxcodecocoa-touch

提问by ConfusedNoob

Possible Duplicate:
Can you reference Xib files from static libraries on the iPhone?

可能的重复:
你能从 iPhone 上的静态库中引用 Xib 文件吗?

I have created an iOS framework and it includes a xib view. When I debugged the program, this line of code worked fine:

我创建了一个 iOS 框架,它包含一个 xib 视图。当我调试程序时,这行代码运行良好:

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];

However, when I 'reference' the framework from another project - the nib is no longer in the 'mainBundle'. What should I do with the code above (that is part of the framework) so it loads from the framework and not the consuming application project?

但是,当我从另一个项目“引用”框架时 - 笔尖不再在“mainBundle”中。我应该如何处理上面的代码(这是框架的一部分),以便它从框架而不是消费应用程序项目加载?

回答by FluffulousChimp

The framework in question should have a bundle identifier in its Info.plistfile typically. In the application that makes use of this custom framework, you should be able to access resources in this bundle by:

有问题的框架Info.plist通常应该在其文件中包含一个包标识符。在使用此自定义框架的应用程序中,您应该能够通过以下方式访问此包中的资源:

NSString *frameworkBundleID = @"com.yourCompany.YourFrameworkBundleID";
NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:frameworkBundleID];

This is the NSBundlefrom which you can access framework resources.

这是NSBundle您可以访问框架资源的来源。

EDIT:

编辑:

There appears to be an alternate (possibly better) means of accessing the bundle in question.

似乎有一种替代(可能更好)的方法来访问有问题的包。

e.g.:

例如:

NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"MyLibraryResources" withExtension:@"bundle"]];

See this excellent tutorial

看到这个优秀的教程