10

重複の可能性:
iPhoneの静的ライブラリからXibファイルを参照できますか?

iOSフレームワークを作成しましたが、xibビューが含まれています。プログラムをデバッグしたとき、次のコード行は正常に機能しました。

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

ただし、別のプロジェクトからフレームワークを「参照」すると、nibは「mainBundle」に含まれなくなります。上記のコード(フレームワークの一部)を使用して、消費するアプリケーションプロジェクトではなく、フレームワークからロードするようにするにはどうすればよいですか?

4

1 に答える 1

19

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:

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

This is the NSBundle from which you can access framework resources.

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

于 2012-09-24T02:10:54.680 に答える