16

I've gone through a bunch of answers regarding this problem but none seem to relate to my problem.

I have two views, View 1 has a button. View 2 has a button.

View 1 button is tied to a model segue to View 2.

I click the Button in View 1, it opens up View 2.

In View 2 the button is connected to an IBAction which fires

[self dismissViewControllerAnimated:YES completion:nil];

Which closes the View and displays View 1 again - Now if I press the Button on View 1 again I get

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <x/y/z/SomeApp.app> (loaded)' with name 'tvz-Io-ndz-view-rB8-bq-l6j' and directory 'Main.storyboardc''

I'm completely lost how to fix this problem. Please help!

EDIT:

  • This only happens when the device doesn't have internet
  • If I have a third screen in the chain with a webview which renders an image, if I goto that screen from View 2 the app doesn't crash.

EDIT 2:

I've also tried rebuilding the screen from scratch.

I'm completely baffled.

EDIT 3: Full Stacktrace

2015-01-19 09:10:58.528 SomeApp[37747:2203364] *** Terminating app due to
 uncaught exception 'NSInternalInconsistencyException', reason: 'Could not 
load NIB in bundle: 'NSBundle     
</Users/user/Library/Developer/CoreSimulator/Devices/D23C1B7C-7330-
466E-8369-762C6727B19C/data/Containers/Bundle/Application/AE67C3D3-C5AE-
4A66-91EC-54D976A4A4FC/SomeApp.app> (loaded)' with name 'tvz-Io-ndz-view-
rB8-bq-l6j' and directory 'Main.storyboardc''

*** First throw call stack:
(
    0   CoreFoundation                      0x01f64946 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x01beda97 objc_exception_throw + 44
    2   CoreFoundation                      0x01f6486d +[NSException raise:format:] + 141
    3   UIKit                               0x008f8e06 -[UINib instantiateWithOwner:options:] + 1003
    4   UIKit                               0x0071b624 -[UIViewController _loadViewFromNibNamed:bundle:] + 270
    5   UIKit                               0x0071bdbb -[UIViewController loadView] + 295
    6   UIKit                               0x0071bfef -[UIViewController loadViewIfRequired] + 78
    7   UIKit                               0x0071c595 -[UIViewController view] + 35
    8   UIKit                               0x00d8f707 -[_UIFullscreenPresentationController _setPresentedViewController:] + 75
    9   UIKit                               0x006f1a81 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 113
    10  UIKit                               0x00729a61 -[UIViewController _presentViewController:withAnimationController:completion:] + 2102
    11  UIKit                               0x0072c5d2 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
    12  UIKit                               0x0072c424 -[UIViewController presentViewController:animated:completion:] + 224
    13  UIKit                               0x0072c8ea -[UIViewController presentModalViewController:animated:] + 57
    14  UIKit                               0x00bf448d -[UIStoryboardModalSegue perform] + 271
    15  UIKit                               0x00be1b49 -[UIStoryboardSegueTemplate _perform:] + 217
    16  UIKit                               0x00be1bc5 -[UIStoryboardSegueTemplate perform:] + 116
    17  UIKit                               0x006d4907 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1490
    18  UIKit                               0x006d4af7 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 285
    19  UIKit                               0x006d9df3 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
    20  UIKit                               0x005ee0ce ___afterCACommitHandler_block_invoke + 15
    21  UIKit                               0x005ee079 _applyBlockToCFArrayCopiedToStack + 415
    22  UIKit                               0x005ede8e _afterCACommitHandler + 545
    23  CoreFoundation                      0x01e879de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    24  CoreFoundation                      0x01e87920 __CFRunLoopDoObservers + 400
    25  CoreFoundation                      0x01e7d35a __CFRunLoopRun + 1226
    26  CoreFoundation                      0x01e7cbcb CFRunLoopRunSpecific + 443
    27  CoreFoundation                      0x01e7c9fb CFRunLoopRunInMode + 123
    28  GraphicsServices                    0x043d524f GSEventRunModal + 192
    29  GraphicsServices                    0x043d508c GSEventRun + 104
    30  UIKit                               0x005c48b6 UIApplicationMain + 1526
    31  SomeApp                             0x000e482d main + 141
    32  libdyld.dylib                       0x027e8ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

James

Forge
  • 6,538
  • 6
  • 44
  • 64
TheBritishAreComing
  • 1,667
  • 2
  • 19
  • 38
  • Can you show the code that presents View 2, just to make sure nothing strange is going on there? – Stonz2 Jan 08 '15 at 14:54
  • @Stonz2 No hand written code right click dragged the button to the Second View and there isn't any additional Segue handling code. – TheBritishAreComing Jan 08 '15 at 15:00
  • there is something missing in your 'teardown' code for view2, some process you've fired off but are not properly cleaning up after. Perhaps view2 is delegate to something and theres a retain cycle ? In my experience this will only happen if the first view2 has not been released properly.. – Jef Jan 18 '15 at 20:07
  • override dealloc in view2 and set a breakpoint. And viewWillDisappear in the event dealloc is never being called (I'm tipping it's not when you don't reach view3) – Jef Jan 18 '15 at 20:17
  • Thanks @Jef I'll give it a try tomorrow when I'm back in the office. Question though why would a app that has no internet features only crash when the internet is disabled on the device? (it works fine if the internet is live on the device) – TheBritishAreComing Jan 18 '15 at 21:28
  • my first guess is that you're not allowing for that eventuality in whatever networking code you're running.. (edit oops, you're not running any?) ads? analytics ? some third party code / library ? – Jef Jan 18 '15 at 21:52
  • Hey @Jef dealloc fires and absolutely nothing network code wise, it's part of a bigger app and I removed everything related. Also if the network isn't running and I display a UIWebView with a local animation on a third view the app doesn't crash. If I don't do this it does I've attached a full stacktrace it's erroring out in core iOS from what I can see thanks – TheBritishAreComing Jan 19 '15 at 09:16
  • Add the code block where you are loading `view2` over `view1` – Mrunal Jan 19 '15 at 09:19
  • @James why "Main.storyboard" is shown as "Main.storyboardc" Why extra letter c is at end – Rupesh Jan 19 '15 at 11:19
  • @Mrunal there is no code, I've literally connected the button to View 2 in the story board editor. Just to test I put a empty prepareForSegue with a break point and a empty viewDidLoad with a break point. First time both break points hit. Second time only the prepareForSegue break point is hit. – TheBritishAreComing Jan 19 '15 at 15:21
  • Rather than having View 2 dismiss itself try having View 2 call into View 1 and dismiss the controller. Something like (in View 2's button action) [self.presentingViewConroller dismissViewControllerAnimated:]. This is what is supposed to happen anyway, but I've read of other people running into memory issues with the way the call forwarding happens. – Mike Gottlieb Jan 19 '15 at 19:09
  • I'm pretty sure that this question is unanswerable (unless you post the entire project). The most likely cause is memory corruption. The difficulty with memory corruption is that the symptom you see (inability to open view2 a second time) is completely unrelated to the cause. The cause (presumably) is in some random piece of code that steps on memory somewhere. One approach is to start with the minimal project, verify that it works, and then build the app piece by piece until it breaks. The other approach is a detailed code review that specifically looks at memory usage. – user3386109 Jan 21 '15 at 21:42
  • here is working solution https://stackoverflow.com/a/56199366/1371853 – swiftBoy May 18 '19 at 13:27

8 Answers8

38

There can be quite a number of reasons that could raise the error you're receiving.

I'll start enumerating some things to check for and solutions:

  1. Have you renamed your xib or storyboard file outside Xcode? If so, check everywhere you have a reference to it for inconsistencies. Also be sure you respect the uppercase / lowercase letters anywhere you reference the file since is case sensitive.

  2. Go to Interface Builder, select your View1 ViewController > Utilities Panel > Identity Inspector > check if the Custom Class corresponds to your ViewController Class if you have one (.h and .m files).

  3. Check your Info.plist file. If you use storyboads, you should have an entry like Main storyboard file base name and NOT Main nib file base name. If you use nibs, then is vice-versa. Also check that the file base name corresponds with name of the actual file.

  4. Check your target's Build Phases > Copy Bundle Resources and make sure that your xib or storyboard file is added there.

  5. If you instantiate your View1 ViewController programmatically and you use xib file check the nib name for typos (remember, is case-sensitive). Also, if you currently append .xib file format to the name, remove the extension because it shouldn't be used. What I mean is this line of code: UIViewController *controller = [[UIViewController alloc] initWithNibName:@"xibFileName" bundle:nil];

  6. Check the properties of your xib or storyboard file in the file inspector and make sure that your file is linked to your target in the Target Membership selection panel.

  7. Check the properties of the xib or storyboard file in the file inspector and try switching your file Location to Relative to project or Relative to group. See if either way makes a difference.

  8. If you're adding your view controller programmatically in the initWithCoder then you should instantiate it in the viewDidLoad method instead

  9. If nothing from above applies to your situation, you could delete the file from Xcode (select Remove References) and import it again in your project.

Remember to ALWAYS clean your project after making the above changes (SHIFT+COMMAND+K).

Please let us know if it worked and what worked.

Razvan
  • 4,122
  • 2
  • 26
  • 44
  • This is a fantastic list of reasons for it. Not sure how you conjured it... but huge thanks! #6 above is what did it for us. =) – Marchy Sep 11 '15 at 18:44
  • My issue was I wasn't using the right bundle... bundle: Bundle(for: – devjme Feb 21 '19 at 23:35
2

I tried all above answer but they didn't work. For me, the solution was to include the xib to the target resource.

Steps performed:

  • Click on xib file.
  • Open Identity Inspector -> Target Membership and check second option (ProjectName_Resource)
Forge
  • 6,538
  • 6
  • 44
  • 64
1

You may have to setup the bundle for the class before accessing the xib:

ObjectiveC:

//Bundle initialisation
NSBundle* bundle = [NSBundle bundleForClass:[self class]];

//Initialising the nib
UIView *nibView = [[bundle loadNibNamed:@"nibFileName" owner:self options:nil] objectAtIndex:0];

//Display the ad (this will vary based on your application setup)
[[[UIApplication sharedApplication] keyWindow] addSubview:nibView];
Mukund Agarwal
  • 575
  • 5
  • 14
1

I faced this when I extracted a .app from a zip file and attempted to run it, both on an iOS device and on Simulator.

One .nib file had been named with non-latin characters (fileNormal.nib with the greek letters No) and when extracted from the zip, it was assigned letters from another charset (it should be Greek-DOS or something compatible). I chose a different charset upon extraction and it worked as it should.

Just putting this in case someone else faces the same problem ;)

kpoustas
  • 11
  • 1
0

You can try and check the below scenarios for the exception:

1) If nib file is missing then add the same in your Xcode

2) Put a check inside IBAction method before dismissing, refer this

Forge
  • 6,538
  • 6
  • 44
  • 64
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

It's also possible the UITableViewDataSource or UITableViewDelegate are not implemented in the desired UIViewController

peterdoesco.de
  • 529
  • 3
  • 19
0

If you're working with cocoapods, it may also help to run pod update. One of my teammates changed a pod around which resulted in that error, so pod update fixed it for me.

Eden
  • 1,782
  • 15
  • 23
0

In my case exact same exception was caused by the fact that two controllers had same storyboard id (within one storyboard)

user1232690
  • 481
  • 5
  • 16