NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: - ios

I'm trying to get Xcode's iphone simulator to display by nib after the launch screen, but I keep getting this error.
Full error:
2015-03-26 21:01:40.462 Hangman Jury[5278:476697] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'HangController''
Relevant code:
in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[HangController alloc] initWithNibName:#"HangController" bundle:nil];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Erroring line in main.m:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
HangController is a simple subclass of UIViewController
Things I've tried:
-Spelling "HangController" correctly
-Making sure View2.xib is included in Copy Bundle Resources
-I have not renamed anything outside of Xcode
-I'm not using storyboards and I have removed storyboard items from Info.plist
-My view is linked to the target in the Target Membership list
Thanks for your help

Related

Universal trying to display different nib files

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xa46e6a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I've been researching this for the past couple of days but I haven't found an answer that gets my app to run.
I have a universal app with two nib files (one for phone, one for pad) and no matter what I change I keep running into this runtime error. I have triple-checked my connections in the Interface Builder. I also defined the main interfaces for both phone and pad respectively.
This is what my AppDelegate.m looks like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ViewController *viewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}else {
viewController = [[ViewController alloc] initWithNibName:#"ViewController-iPad" bundle:nil];
}
self.window.rootViewController = viewController;
[viewController release];
[self.window makeKeyAndVisible];
return YES;
}
I would like to suggest to check your xib files of ViewController.
Is the custom class of file's owner set to ViewController?
and view outlet connected to file's owner?
and then try it again.

How to add/connect NIB to programmatically created UINavigationController?

First of all, I'm a beginner, so I might have my concepts wrong.
This is my code in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"FirstView" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
The idea is to programmatically add UINavigationController, but then use a .xib (the "FirstView" paremeter) for the views. I have no problem with programmatically creating the views as well, but for simpler interfaces, I assume using IB can be done as well.
However, when I run the code, I get this error:
2013-07-11 21:20:42.644 new-book-proto-01[64308:11303] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.'
What should I do? Is there anything missing?
Additionally, is something like this common in iOS development? Is it bad practice? Is there a better way to do this?
This is the reason as told: "reason:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstView" nib
but the view outlet was not set.' "
It means that you try to access or get value for some views (UI elements) that has not IBOutlet in your controller class or you have none view at all
You should create IBOutlets (properties) for each view (each UI element is view) that you would like to "see" in your controller

Change initial View Controller of Master-Detail-Application

I created a new iPhone project on a Master-Detail-Application. As I need a login before, I added at the storyboard a new ViewController, checkmarked "is initial View Controller" and assigned the new created class LoginViewController to this ViewController.
Furthermore but not relevant (in my opinion), i created a segue and connected it from the ViewController to the NavigationController (of the Master-Detail-Template).
The AppDelegate.m was changed to launch the new controller at startup:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
/* // Old Master-Detail-View-Controller
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
*/
(LoginViewController *)self.window.rootViewController;
return YES;
}
This will end up in the error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UICollectionViewController loadView] loaded the "Qn5-Rj-iPA-view-IRE-eP
-ILZ" nib but didn't get a UICollectionView.'
I have as well tried this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
LoginViewController *loginViewController = [[LoginViewController alloc] init];
self.window.rootViewController = loginViewController; //Set the view controller
[self.window makeKeyAndVisible];
return YES;
}
Resulting in a similar error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'UICollectionView must be initialized with a non-nil layout parameter'
Where is my mistake?
What I do not get is, where the hell the UICollectionView in the error message comes from. I did never create one or add one??
My LoginViewController inherits by mistake form UICollectionViewController instead of UIViewController. I fixed that and it works.
This explained the strange errormessage which i did not understood in the first place. As always the truth is in the sourcecode. Rechecking helps.
You don't have to do anything to load view controllers in the AppDelegate. As long as your stroyboard is the one that is loaded in project settings, it should load automatically.

Unique Issue displaying first storyboard scene in Xcode

I have tried for 2 days now to get my storyboard to display with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *LoginViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = LoginViewController;
[self.window makeKeyAndVisible];
return YES;
}
However, I keep getting this error and a sigbart in my main: 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainStoryboard' in bundle NSBundle (loaded)'
Nothing seems to appear in google about these errors? Does anyone have any idea how to fix it?
Update: When I change it to:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *LoginViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = LoginViewController;
[self.window makeKeyAndVisible];
return YES;
}
it gives me the errors:
[3208:c07] The app delegate must implement the window property if it wants to use a main storyboard file.
{AppDelegate setWindow:]: unrecognized selector sent to instance 0x962bf30
[3208:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate setWindow:]: unrecognized selector sent to instance 0x962bf30'
Finally Found It!!!!!! Turns out that I forgot to put this line of code in the app delegate header file:
#property (strong, nonatomic) UIWindow *window;

Crash when loading main xib on iPad only in universal app?

I have a universal app but this issue seems to only relate to the iPad and not the iPhone since the iPhone version loads the correct XIB.
So pretty much the issue is, it is not loading my main XIB for my app. I named the XIB's like so:
For iPhone: MyViewController.xib
For iPad: MyViewController_iPad.xib
Also I deleted my MainWindow.xib because in the template project for a universal app it shows no MainWindow.xib anywhere.
This is how I am trying to load the view on app launch:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController" bundle:nil] autorelease];
} else {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
This is the crash info:
A SIGABRT on this line [self.window makeKeyAndVisible];
And this is the crash log:
2011-12-07 07:37:46.560 ocrapi[763:607] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/29F4CD7A-149E-46EA-B280-3D188PP19D17/.app> (loaded)' with name 'MyViewController_iPad''
Edit1:
Here is the message:
warning: No copy of <No file name> found locally, reading from memory on remote device. This may slow down the debug session.
Also if I click on my products then do show in finder, then do show package contents, MyViewController.xib or MyViewController_iPad.xib is not there. Is it supposed to be like that?
Make sure your nib really really really is called MyViewController_iPad.xib, with that exact capitalization.
Make sure the xib file is in your target's list of things to be copied to the app on build.
Finally, make sure you've no Main Nib setting still in your Info.plist file.
Oh, and one more thing. There is no need for this code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController" bundle:nil] autorelease];
} else {
self.viewController = [[[ocrapiViewController alloc] initWithNibName:#"MyViewController_iPad" bundle:nil] autorelease];
}
Simply call initWithNibName:#"MyViewController". If your iPad nib is named MyViewController~ipad.xib (note the twiddle, note the lowercase "ipad") it will be chosen automatically when you're on an iPad.

Resources