Search code examples
iosxcodenibnsexception

Cannot load nib file, however file exists there


I wanted to create a new view controller, which would be home view controller. However, somehow I couldn't managed to find how this exception is thrown. Having tried restarting XCode, restarting computer, clean project, delete from simulator. Nothing solved. Here are the details:

This is the exception thrown.

Exception

Xcode's Finder View is like this

Xcode Finder View

The actual folder of app

OS X Finder View

The code block where nib is loaded

#pragma mark - View's life cycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    UINib *nib = [UINib nibWithNibName:@"MainMenuCell.xib" bundle:nil];

    [self.tableView registerNib:nib forCellReuseIdentifier:@"MainMenuCell"];

    self.tableView.delegate = self;
}

The parent view controller of nib owner is declared

@implementation BNRAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launches

    self.window.rootViewController = [[MainMenuViewController alloc] init];

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

Nib's implementation file (MainMenuCell.m)

#import "MainMenuCell.h"

@implementation MainMenuCell

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

Reuse Identifier declared inside IB

Attributes 1 - MainMenuCell

nib's Custom Class

Attributes 2 - MainMenuCell

Copy Bundle Resources of app in Build Phases

Build Phases 1

Compiled Sources of app in Build Phases

Build Phases 2

There are too much images I apologize for that, but I've taken screenshot of everything in order to check my consistency. Any idea will be greatly welcomed (having lost like 5 hrs there!!!).


Solution

  • You do not need to specify the file extension in your nib loading code. Cocoa automatically handles this for you.

    UINib *nib = [UINib nibWithNibName:@"MainMenuCell.xib" bundle:nil];

    Should be:

    UINib *nib = [UINib nibWithNibName:@"MainMenuCell" bundle:nil];