Could not load NIB in bundle: 'NSBundle' in ios?

Hi, I have a view that contains a tableview in my app. I use cellForRowAtIndexPath function to populate tableview. But it crashes sometimes and throws an error like below. It occurs rarely but I want to solve it!

Code part :


(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {

        if (self.productViewType == ProductToShelfViewTypeShelf) {

            static NSString* cellIdentifier = @"ShelfCell";
            ShelfCellView* cell = (ShelfCellView*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (cell == nil) {
                NSArray* nibObjects = [[NSBundle mainBundle] loadNibNamed:@"ShelfCellView" owner:nil options:nil];
                for (id currentObject in nibObjects) {
                    if ([currentObject isKindOfClass:[ShelfCellView class]]) {
                        cell = (ShelfCellView*)currentObject;
                    }
                }
                [cell initViewStyles];
            }

            Shelf* shelf = [self.shelfList objectAtIndex:indexPath.row];
            cell.shelf = shelf;
            [cell initView];
            return cell;
        }
        else {
            static NSString* cellIdentifier = @"ProductToShelfCell";
            ProductToShelfCellView* cell = (ProductToShelfCellView*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (cell == nil) {
                NSArray* nibObjects = [[NSBundle mainBundle] loadNibNamed:@"ProductToShelfCellView" owner:nil options:nil];
                for (id currentObject in nibObjects) {
                    if ([currentObject isKindOfClass:[ProductToShelfCellView class]]) {
                        cell = (ProductToShelfCellView*)currentObject;
                    }
                }
                [cell initViewStyles];
            }
            Product* product = [self.products objectAtIndex:indexPath.row];
            cell.product = product;
            [cell initView];
            return cell;
        }

        return nil;
    }



Stacktrace :


   Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/B07CBD90-32C2-4F41-ADB0-11AA6422AFF3/Myapp.app> (loaded)' with name 'ProductToShelfCellView'
        Fatal Exception: NSInternalInconsistencyException
        0  CoreFoundation                 0x1f576e07 __exceptionPreprocess
        1  libobjc.A.dylib                0x1e7d7077 objc_exception_throw
        2  CoreFoundation                 0x1f576d4d -[NSException initWithCoder:]
        3  UIKit                          0x24aa5007 -[UINib instantiateWithOwner:options:]
        4  UIKit                          0x24aa726b -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:]
        5  Kitapyurdu                     0x50321 -[ProductToShelfViewController tableView:cellForRowAtIndexPath:] (ProductToShelfViewController.m:429)
        6  UIKit                          0x249027fb -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:]
        7  UIKit                          0x249029e5 -[UITableView _createPreparedCellForGlobalRow:willDisplay:]
        8  UIKit                          0x248ef1ef -[UITableView _updateVisibleCellsNow:isRecursive:]
        9  UIKit                          0x24907ae1 -[UITableView _performWithCachedTraitCollection:]
        10 UIKit                          0x246ad345 -[UITableView layoutSubviews]
        11 UIKit                          0x245c65d5 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
        12 QuartzCore                     0x223ec109 -[CALayer layoutSublayers]
        13 QuartzCore                     0x223e031f CA::Layer::layout_if_needed(CA::Transaction*)
        14 QuartzCore                     0x223e01af CA::Layer::layout_and_display_if_needed(CA::Transaction*)
        15 QuartzCore                     0x22370a6b CA::Context::commit_transaction(CA::Transaction*)
        16 QuartzCore                     0x2238f035 CA::Transaction::commit()
        17 UIKit                          0x2484891f _UIApplicationFlushRunLoopCATransactionIfTooLate
        18 UIKit                          0x24d6388f __handleEventQueue
        19 CoreFoundation                 0x1f532c8b __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
        20 CoreFoundation                 0x1f532795 __CFRunLoopDoSources0
        21 CoreFoundation                 0x1f530a6b __CFRunLoopRun
        22 CoreFoundation                 0x1f480073 CFRunLoopRunSpecific
        23 CoreFoundation                 0x1f47fe81 CFRunLoopRunInMode
        24 GraphicsServices               0x20c2cbfd GSEventRunModal
        25 UIKit                          0x2463482f -[UIApplication _run]
        26 UIKit                          0x2462ef61 UIApplicationMain
        27 Kitapyurdu                     0x222fb main (main.m:16)
        28 libdispatch.dylib              0x1ec4a50b (Missing)

Trying to load the nib from storage for each cell when an existing cell is unavailable for reuse will kill performance. You are better off registering your nib ahead of time with register(_ nib: UINib?, forCellReuseIdentifier identifier: String) when you load your table view.

I am facing a similar issue. Was this resolved?

Is there any particular reason you're using "dequeueReusableCell(withIdentifier:)" instead of "dequeueReusableCell(withIdentifier:for:)"? The second one can't return nil, so you don't need the extra code to create a cell "manually".


Are you seeing only an intermittent problem? Can you characterize the cases where it fails?

I have posted my question here https://forums.developer.apple.com/message/240995#240995

I am facing this issue while pushing a view controller and it ocurres rarely too.

My issue was related to the Main Interface property on the General tab being set to a value of 'roo'. Which I don't know where that came from.

Once I set it to 'LaunchScreen-iPhone.storyboard', it compiled.

Could not load NIB in bundle: 'NSBundle' in ios?
 
 
Q