Question : iPhone, how do I correctly pass data model object data between various view controllers without breaking MVC?

Hello,
           I am still learning the iphone sdk and got stuck on effectively being able to pass a model object between various view controllers.  The scenario is basically as follows:  I have a parent view controller that i am utilizing to switch between 4 different child view controllers.  Naturally the parent view controller would need to hold a pointer model object that could be shared amongst the child view controllers.  Well thats where im stuck.  I DO NOT want to use the "global" methods that ive seen all over the internet and somehow think that it makes sense here to setup some type of delegate at the parent view controller level and allow that to delegate between the four child views.  Now its easy to go from parent to child by initalizing a method on the child but I CANT seem to find a working example anywhere to do what im trying to do correctly.  I have attempted to setup a "protocol" but, as ive said have had absolutely no love! :(  Ive attached some of the code ive been working with.  I would welcome some help!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
ParentViewController.h

@protocol virtualTerminalSwitchProtocol <NSObject>
@optional
	@property (retain,nonatomic) Transaction *transaction;
@end

@interface VTSwitchViewController :<virtualTerminalSwitchProtocol>{

	id<virtualTerminalSwitchProtocol> delegate;
	
}


@property (assign) id<virtualTerminalSwitchProtocol> delegate;


ParentViewController.m

	VirtualTerminalViewController *virtualTerminal = [[VirtualTerminalViewController alloc] initWithNibName:@"VirtualTerminalView" bundle:nil];

	[virtualTerminal setDelegate:delegate];
self.virtualTerminalViewController = virtualTerminal;
	[self.view insertSubview:virtualTerminal.view atIndex:0];

NO CLUE WHAT TO DO ON CHILD CONTROLLERS

Answer : iPhone, how do I correctly pass data model object data between various view controllers without breaking MVC?

Actually, I saw this approach with the delegate in one great book "Cocoa and Objective-C Up and Running". Almost in the end of thsi book there is a big project (a photo gallery). All source are there. I think this or a similar example exists on the developer.apple.com. Look for something about Core Data.

I cannot say that I understand your approach from the question, so I can be wrong, but I do not see how it can break MVC. Also I'm not getting mad about all these controllers - if an application have few controls, I will handle them from the app delegate generated by Xcode (3.2.2 and 3.2.3 Xcode add the app delegate when you create new Cocoa project). My projects are for Mac OS.

Random Solutions  
 
programming4us programming4us