Adnan Khan
Adnan Khan

Reputation: 917

Two nib files connect with .h and .m?

I developed an app in iphone now i need to also create this same app on ipad, I have the following files

LoginViewController.h
LoginViewController.m
LoginViewController.xib

now i added new file for ipad:

LoginViewController~ipad.xib

now i am getting an error:

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

Upvotes: 2

Views: 534

Answers (1)

Nitin Gohel
Nitin Gohel

Reputation: 49730

There are some step to go:-

  • create New Xib for Ipad like you say LoginViewController~ipad.xib and open it.

  • click on file Owner--> and like bellow:-

enter image description here

now your ipad xib is also with your Loginviewcontroller customeClass

  • now you just need to check it IsIphone or Ipad like:-

#import "Homeviewcontroller.h"

#import "LoginViewController.h"

#define isIpad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //define here above implementation method

@implementation Homeviewcontroller

now if you want newNib load after crating as par above image you can load like bellow:-

if(isIpad)
{
   LoginViewController *ObjLoginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController~ipad" bundle:nil];
}
else
{
   LoginViewController *ObjLoginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
}

EDIT

Connect your FileOwner to main view like:-

enter image description here

Upvotes: 3

Related Questions