NSInternalInconsistencyException, reason: Could not load NIB in bundle

后端 未结 8 1983
轻奢々
轻奢々 2020-12-03 08:55

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.

相关标签:
8条回答
  • 2020-12-03 09:22

    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.

    0 讨论(0)
  • 2020-12-03 09:22

    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

    0 讨论(0)
提交回复
热议问题