简体   繁体   English

如何使用通过.h文件放置的静态库迁移的.xib文件?

[英]How to to use .xib file migrated with the static library placed with .h files?

I created a static library which is having .xib file along with classes I want to use that .xib file and further want to create the .framework from it b. 我创建了一个静态库,其中包含.xib文件以及我想使用该.xib文件的类,并进一步希望从中创建.framework b。 But the scene is that when I dragged the static library project I have access to all classes and its objects but not to the ViewController.xib this is AppDelegate.h 但是场景是,当我拖动静态库项目时,我可以访问所有类及其对象,但不能访问ViewController.xib这是AppDelegate.h

#import <UIKit/UIKit.h>

#import <StaticLibProject/ViewController.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property(strong , nonatomic) ViewController *viewControllerObject;


@end

AppDelegate.m AppDelegate.m

@synthesize viewControllerObject;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    viewControllerObject =[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    viewControllerObject.view.frame=CGRectMake(0, 0, 320, 567);

    [self.window addSubview:viewControllerObject.view];

    return YES;
}

And I am getting the following error 我收到以下错误

2015-02-05 13:43:00.255 AppsLibTest[1012:297168] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/mobile/Containers/Bundle/Application/2C4BF742-2B3C-4978-957F-D99D8D54D422/AppsLibTest.app> (loaded)' with name 'ViewController''
*** First throw call stack:
(0x183f9a59c 0x1946ac0e4 0x183f9a4dc 0x188b57448 0x188a5c274 0x18874c844 0x18874c7b0 0x10001d100 0x1887be00c 0x1889d4fd4 0x1889d7754 0x1889d5dec 0x18c21162c 0x183f52a28 0x183f51b30 0x183f4fd30 0x183e7d0a4 0x1887b73c8 0x1887b23c0 0x10001d5b8 0x194d1aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException

If you have bundled the xib file, you can try this: 如果您捆绑了xib文件,则可以尝试以下操作:

NSBundle *bundle = [NSBundle bundleForClass:[ViewController class]];
viewControllerObject = [[ViewController alloc] initWithNibName:@"ViewController" bundle:bundle];

if bundle is nil, then you need to check how you package your framework. 如果bundle为nil,则需要检查如何打包框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM