could not load NIB in bundle.No storyboard or xib

I am learning to code in this language so please bare with me and my niave question.

I had lots of problems with using storyboard getting stuck with code signing errors (you may have seen my questions in the forum) so I decided that as I was not doing anything complex I would simplify the code so removed the reference to the storyboard and its entry in the plist.

I am now trying to get the flow of the app to work without storyboard or xib.

The build goes fine but the run stops with the debug error summary containing the error about NIB not in bundle.

Ive tried googling but ended up getting lost in all the instances of this error where storyboard and or XIB was involved.

I dont have an xib or storyboard.

Anyone give me a pointer as to where I am going wrong?


Reference information below here. If more is needed please let me know.

The app in the navigator looks like this:

mouse4cat

mstAppDelegate.h

mstAppDelegate.m (code in reference below)

mstViewController.h

mstViewController.m ( functionality in here is mainly to establish and move a mouse image arround in the view)

Images.xcassets (contains the icons and default images)

Supporting Files (contains the images for the mouse animations)


AppDelegate contains:

//
// mstAppDelegate.m
// mouse4cat
//
// Created by major on 13/10/2017.
// Copyright (c) 2017 major. All rights reserved.
//

#import "mstAppDelegate.h"

#import "MSTViewController.h"

@implementation mstAppDelegate

@synthesize mstViewController = _mstViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *mstViewController = [[UIViewController alloc] initWithNibName:@"mstViewController" bundle:[NSBundle mainBundle]];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mstViewController];

self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

Accepted Reply

You say you have no xib nor storyboard, but call initWithNibName.


How is it ?

Replies

You say you have no xib nor storyboard, but call initWithNibName.


How is it ?

Thanks for the response.

I have no xib or storyboard file.

I copied the syntax of the line

UIViewController *mstViewController = [[UIViewController alloc] initWithNibName:@"mstViewController" bundle:[NSBundle mainBundle]];

from a running example that did have a storyboard. I just changed the names of the bits to my names.

What should I have coded?

I am not sure of the process flow between Delegate and Controller.

Is there somewhere I can read more about this?

Why don't you want to use xib or storyboard ? That makes life really simpler.


Otherwise, you need to create the viewController and create all the objects inside … really more complex.


When you create a controller and ask for creating its xib altogether (or create in a storyboard), the window's delegate is set to the controller automatically.

It just says that the controller will be the delegate (ie, it implements functions that are needed by the window) : when window needs to call those func, it passes it to the controller which does the job for it, by delegation.

Than you for your response.

I did go through the earier route but got stuck because I'm using xcode 6.4 and target of iOS 5.1 as this app needs to run on an old iPad 1.

The problem I got there was that the build kept failing with code sign errors and so I decided to go to a base start and work from there.

I have since my original post been going through a tutorial that does the coding without the additional automation.

Having done that I have noticed that I was not using the ViewController class I have established in the mstViewController.m file.

The line I had was

UIViewController *mstViewController = [[UIViewController alloc] initWithNibName:@"mstViewController" bundle:[NSBundle mainBundle]];

but I believe it should be

mstViewController *mstViewController = [[mstViewController alloc] initWithNibName:@"mstViewController" bundle:[NSBundle mainBundle]];

but now I get a warning flag that states

instance method '-alloc' not found (return type defaults to 'id')

with a Fix-it that does nothing.

mstViewController.h contains

//

// mstViewController.h

// mouse4cat

//

// Created by major on 13/10/2017.

// copyright (c) 2017 major. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface mstViewController : UIViewController;


@end

Ok after more digging and trying I found I still had the code wrong.

I was trying to use the class with a pointer with the same name but that wasnt being accepted.

Now I am using

mstViewController *mstRootViewController = [[mstViewController alloc] initWithNibName:@"mstRootViewController" bundle:[NSBundle mainBundle]];

self.window.rootViewController = mstRootViewController;


The build goes ok but the run stops with the Inconsistancy Exception not able to find Nib (mstRootViewController now) in bundle message that I was trying to resolve by using a more basic start.

I did try with bundle:nil but same runtime message.

Anyone any ideas why its looking to load this instance of my class when as far as I know its created in memory and has no overides so runs the base class which is in the mstViewController.m file which is a target member of the app.

Right. Got it.

I coded the connection for the root view controller with a requirement for a nib in a bundle.

As there is no file involved being as this item is an instance of a class that is in a file associated with the target I dont need a bundle.

changed code to

mstViewController *mstRootViewController = [[mstViewController alloc] init];


Now it works and is delivered to my iPad and runs all be it has some movement bugs but this particular problem of looking for a nim thats not necessary has been solved.