iOS - loading xib from bundle in Documents directory

后端 未结 4 525
故里飘歌
故里飘歌 2021-02-06 05:38

I\'ve been working on getting \"custom skinnable\" interfaces working for my iOS app by bundling up xibs and downloading bundles, and loading the xibs in those bundles.

相关标签:
4条回答
  • 2021-02-06 05:50

    Excerpt from the Resource Programming Guide:

    In UIKit, applications can load nib files only from their main bundle..

    Doesn't sound like you can do what you're wanting to do. Or at least, Apple doesn't want you to do it. You can, of course, always download a .bundle with images and load them as UIImage or similar, and then save the "active" skin into a known directory which is the directory your app always looks for the images to use when displaying the interface. Changing the skin equates to replacing the image resources at that path with ones from a downloaded bundle.

    0 讨论(0)
  • 2021-02-06 06:01

    Following the instructions here works:

    loading NSBundle files on iOS

    I was just creating the bundle incorrectly!

    You need to create the bundle in Xcode though because if you don't, it won't be loaded. To create, Add a New Target to your project, choose Framework & Library -> Bundle, and link to Core Foundation. Then add the xibs you want to upload to the web to the target. Build target, reveal it in Finder, compress, and upload!

    0 讨论(0)
  • 2021-02-06 06:04

    First of all if a bundle is not created properly it will not get loaded. So in-order to create a proper bundle below are the steps for creating a bundle:

    1. Add a new target by choosing a template named bundle under OS X -> Framework & Libraries.

    2. Select newly created target and change BaseSDK from OSX to Latest iOS.

    3. Add .xibs, images or other resources which you want to use it from bundle in Build Phrases -> Copy Bundle Resources.

    4. Add CoreFoundation framework in Build Phrases -> Link binary with Libraries.

    5. Compile the target choosing iOS Device.

    6. Save the newly created bundle from Products directory to some place.

    Now copy that bundle into your main project. Load a bundle using below code:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"BundleName" ofType:@"bundle"];
    NSBundle *bundle = [NSBundle bundleWithPath:path];"
    

    You are now set with the new bundle.

    0 讨论(0)
  • 2021-02-06 06:12

    After a good amount of time I figured out that this is a commonly faced problem of loading the resources via library. I was missing the step to add "CoreFramework" to link into the resource bundle and also was not copying it to the client application folder. These steps will help loading the resource bundle appropriately. #dsiddhapura's hint helped me identify these issues.

    0 讨论(0)
提交回复
热议问题