Passing NSManagedObjectContext to Views with Interface Builder
I starte iPhone Development five days ago.
To learn some techniques I created a view based demo application. Now I want to integrate Core Data in my app and run into a typical mvc "problem": Passing data between view. I read several postings here on stackoverflow (i.e. this one) but they doesn't cover the case if somebody wants you use the IB and not manually assign viewcontrollers to a parent tab/navigationcontroller.
You can see my IB Layout below. I want to declare a NSManagedObjectContext in my AppDelegate and pass it to each SubViewController (Like FriendsView or LocationView).
What's the best practice here? I cannot use any custom init methods because the viewcontrollers are created by the nib file.
If you need further information or code, just comment and I'm going to post it asap.
Thanks, Henrik
Screenshot 1
alt text http://dl.dropbox.com/u/357开发者_StackOverflow576/saves/IB/window.pngScreenshot 2
alt text http://dl.dropbox.com/u/357576/saves/IB/viewcontroller_attr.pngDeclaring the Context in my app delegate was the best thing to do
You can access it by using
NSManagedObjectContext *context = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
I doubt LocationViewController is a base IB object. Therefore, you have access to the LocationViewController.m file and can alter its init method.
If you don't want to mess with init, you could just override viewDidLoad: as well.
Hope this helps.
or use the - (void)awakeFromNib
method to alter data through code.
精彩评论