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

时间:2015-02-05 08:25:06

标签: ios objective-c

我创建了一个静态库,它具有.xib文件和类 我想使用.xib文件,并希望从中创建.framework b。 但现场是,当我拖动静态库项目时,我可以访问所有类及其对象,但不能访问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

@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;
}

我收到以下错误

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

1 个答案:

答案 0 :(得分:0)

如果您已捆绑xib文件,可以尝试:

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

如果bundle为零,那么您需要检查如何打包框架。