Unable to use iOS framework which is internally using .xib file

前端 未结 8 2268
你的背包
你的背包 2020-12-16 19:14

I am trying to make a universal framework, for iOS by following steps specified in this URL: Universal-framework-iOS

I have a viewController class within, that frame

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 19:24

    The simplest way is to use [NSBundle bundleForClass:[self class]] to get the NSBundle instance of your framework. This won't enable the ability to get the framework's NSBundle instance by its Bundle ID but that isn't usually necessary.

    The issue with your code is the initWithNibName:@"Name" bundle:nil gets a file named Name.xib in the given bundle. Since bundle is nil, it looks in the host app's bundle, not your framework.

    The corrected code for the OP's issue is this:

    /*** Part of implementation of ViewControllerWithinFramework class, which is inside the framework ***/
    
    - (id)initWithTitle:(NSString *)aTitle
    {
       NSBundle *bundle = [NSBundle bundleForClass:[self class]];
       self = [super initWithNibName:@"ViewControllerWithinFramework" bundle:bundle];
    
       // ... 
    
       return self;
    }
    

    The only thing changed is giving the correct bundle instance.

提交回复
热议问题