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”中。我应该如何处理上面的代码(这是框架的一部分),所以它从框架而不是消费的应用程序项目加载?
1 个解决方案
#1
15
The framework in question should have a bundle identifier in its Info.plist
file 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 NSBundle
from 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"]];
看到这个优秀的教程
#1
15
The framework in question should have a bundle identifier in its Info.plist
file 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 NSBundle
from 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"]];
看到这个优秀的教程