1. 新建一个静态库工程bundle

wKioL1MX23bSrpoCAALysr0GArY054.jpg

2. 新建一个Viewcontroller

wKioL1MX29uhoj12AAH2Jw08dek092.jpg


3. 新建一个Target Bundle并指定SDK为iOS, 并将TestViewController.xib加到Copy Bundle Resouce

wKiom1MX3OTgf7uWAAQt1U2JFlc733.jpg


wKioL1MX3WKCFhy9AAJWnCdzgyA552.jpg


5. bundle 代码如下


#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface bundle : NSObject
- (void) addViewController:(UIView *)view;
@end
#import "bundle.h"
#import "TestViewController.h"
@implementation bundle
- (void) addViewController:(UIView *)view
{
    NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Test" withExtension:@"bundle"]];
    TestViewController *testCtrl = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:bundle];
    [view addSubview:testCtrl.view];
}
@end

6. 新建一个工程TestBundle, 把libbundle.a,Test.bundle拖入到工程中,然后调用即可

wKioL1MX36jAaW1ZAAJ4VyBDvtE774.jpg

#import "ViewController.h"
#import "bundle.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
           
    bundle * addView = [[bundle alloc] init];
    [addView addViewController:self.view];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

wKioL1MX4W7QRqbvAAL6KhAU_zM658.jpg