Unable to access managed object context when initializing view

I am using the MainWindow.xib file, which has the following configuration:

MainWindow.xib

  • UITabBarController
    • UINavigationBarController
      • UITableViewControllerAlpha
    • UINavigationBarController
      • UITableViewControllerBeta li>
    • UINavigationBarController
      • UITableViewControllerCharlie

But based on the following message: Why does the initialization of Core Data fail when I try to do this at these points? and the breakpoints that I posted, I came to the conclusion that initWithCoder is used to initialize all UITableViewControllers and that there is no way to reliably use managedObjectContext at this point in the application life cycle.

Does this mean that I have to throw away all the "light" design work and layout that I performed in MainWindow.xib and do it programmatically? Is using master data really means you cannot use NIB files? Or is there some kind of middle earth?

Please let me know, thanks!

0
source share
1 answer

No problem using Core Data, table views and NIB together. I assume that you need to get some objects from the MOC for your view in the table, and you have trouble finding the MOC when you need it.

This approach works for me:

  • Define the final primary interface.
  • nav nib.
  • managedObjectContext applicationDidFinishLaunching:
  • Fetch from MOC viewDidLoad

, :

  • controlObjectContext applicationDidFinishLaunching:
  • viewDidLoad initWithCoder.

, - :

  • controlObjectContext applicationDidFinishLaunching:, , . , .

  • , loadDataFromMOC:, MOC applicationDidFinishLaunching:.

0

Source: https://habr.com/ru/post/1727665/


All Articles