简体   繁体   中英

Add multiple XIB file to any file

I want to add a XIB file ..I have a UIViewcontroller subclasses file ..With one ipad XIB now I want the XIB file with iphone ..

From New File> User Interface >View , I added the new XIB ...Now how do I configure with my existing .h .m .I am unable to connect the File Owner outlet property and By using code If i run this XIB file, gives me crass error saying

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "AViewController_iphone" nib but the view outlet was not set.'

what all changes do i need changes in XIB to use with my .h .m

看看这个快照你可以改变它:

copy your .h file name > go to your target xib file > click on files owner > click on third tab from the right side menu bar on that on upper right corner paste your copied text at the box of class and then assign your view's file owner by right click on view and then drag and drop to files owner

在此输入图像描述

OPen the xib and then click on FIle OWner ..and then Open Identity Inspector and then Under Custom Class section ,,type your class name to which you want to link with,,after that ,,you will see all your connection in file Owner.

Then go to .m file replace previous method with this ...

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
//MainMenu_iPad is xib for iPad and MainMenu is for iPhone
     NSString *nib = (isiPad) ? @"MainMenu_iPad" : @"MainMenu";
    self = [super initWithNibName:nib bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

In .h file

#define isiPad      ([[UIDevice  currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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