tags:

views:

137

answers:

3

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

Screenshot 2
alt text

+1  A: 

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.

refulgentis
Indeed, LocationViewController is a custom subclass of UIViewController, but is initWithNib called when I define my SubViewController in my nib (Screenshot 2)
Henrik P. Hessel
+1  A: 

or use the - (void)awakeFromNib method to alter data through code.

natanavra
+1  A: 

Declaring 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];
Henrik P. Hessel